#!/usr/bin/env python
# coding=utf-8 import threading
import requests
import Queue
import sys
import re
import time
import warnings
import datetime
import argparse __author__ = 'depycode' warnings.filterwarnings("ignore") #ip to num
def ip2num(ip):
ip = [int(x) for x in ip.split('.')]
return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3] #num to ip
def num2ip(num):
return '%s.%s.%s.%s' %((num & 0xff000000) >>24,
(num & 0x00ff0000) >>16,
(num & 0x0000ff00) >>8,
num & 0x000000ff )
#
def ip_range(start, end):
return [num2ip(num) for num in range(ip2num(start), ip2num(end) + 1) if num & 0xff] #
def bThread(iplist): threadl = []
queue = Queue.Queue()
for host in iplist:
queue.put(host) for x in xrange(0, int(SETTHREAD)):
threadl.append(tThread(queue)) for t in threadl:
t.start()
for t in threadl:
t.join() #create thread
class tThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue def run(self): while not self.queue.empty():
host = self.queue.get(block=False)
try:
checkServer(host)
except:
continue def checkServer(host):
UA = {'user-agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'}
ports = [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,8000,8001,8002,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8888,9002,443,873,2601,2604,4848,8008,8880,9999,3128,5432,2049,7001,9200,9871,4440,6082,8099,8649,9000,9090,50000,50030,50070]
#ports = [80,8080]
for k in ports:
try:
if k==443:
aimurl = "https://"+host
#print aimurl
response = requests.get(url = aimurl,headers = UA,verify=False,timeout = 8)
else:
aimurl = "http://"+host+":"+str(k)
#print aimurl
response = requests.get(url = aimurl,headers = UA,timeout = 8)
#print response.headers
status = response.status_code
try:
serverText = response.headers['server']
except:
serverText = ""
try:
titleText = re.findall(r'<title>(.*?)</title>',response.content.decode('utf-8','ignore').encode('utf-8','ignore'))[0]
except:
titleText = "" saveData = {"ip":host,"port":str(k),'aimurl':aimurl,"status":status,"server":serverText,"title":titleText}
print saveData
Data.append(saveData)
except:
pass def cmd():
iplist_a = []
parser = argparse.ArgumentParser(description='GET TITLE .. Author::depycode')
group = parser.add_mutually_exclusive_group() group.add_argument('-i',
action="store",
dest="iprange",
help="useage:: python gettitle.py -i 10.100.1.1-10.100.1.254",
)
group.add_argument('-f',
action="store",
dest="ipfile",
help="usage:: python gettitle.py -f ip.txt",
type=str,
)
args = parser.parse_args()
ipfile = args.ipfile
ip = args.iprange
if ip:
iplist_a = ip_range(ip.split('-')[0], ip.split('-')[1]) elif ipfile:
iplist_tmp = open(ipfile).readlines()
for i in iplist_tmp:
iplist_a.append(i.strip()) else:
parser.print_help()
exit()
return iplist_a def report(data):
t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))
f = open('Title'+'-'+str(t)+".html","w+")
table1 = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'><table border='1'>\n<tr><th>url</th><th>stauts_code</th><th>server</th><th>title</th>\n"
f.write(table1)
for i in data:
rows = "<tr><td><a target='_blank' href='%s'>%s</a></td><td>%s</td><td>%s</td><td>%s</td></tr>\n" %(i['aimurl'],i['ip']+":"+i['port'],i['status'],i['server'],i['title'])
f.write(rows)
table2 = "</table>"
f.write(table2)
f.close() def report2txt(data):
t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))
f = open("ip-"+t+".txt","w+")
for i in data:
url = i['aimurl']
f.write(url)
f.write("\n")
f.close() if __name__ == '__main__': global SETTHREAD
global Data
Data = []
starttime = datetime.datetime.now() try:
SETTHREAD = 200 iplist = cmd() print '\n[INFO] Will scan '+str(len(iplist))+" host...\n" bThread(iplist)
except KeyboardInterrupt:
print 'Keyboard Interrupt!'
sys.exit()
report(Data)
report2txt(Data)
endtime = datetime.datetime.now()
print "Finished in "+str((endtime - starttime).seconds)+"S"

  

usage: getTitle.py [-h] [-i IPRANGE | -f IPFILE]

GET TITLE .. Author::depycode

optional arguments:
-h, --help show this help message and exit
-i IPRANGE useage:: python gettitle.py -i 10.100.1.1-10.100.1.254
-f IPFILE usage:: python gettitle.py -f ip.txt

python gettitle.py的更多相关文章

  1. python gettitle v2.0

    #!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...

  2. python调用py中rar的路径问题。

    1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...

  3. Python pydoc.py

    1. 查看帮助,我们可以在python命令行交互环境下用 help函数,比如: 查看 math 模块: >>> help('math')Help on built-in module ...

  4. django 1.7之后python manage.py syncdb没有了

    在命令行输入python manage.py createsuperuser按照提示输入即可记得先初始化表. django>1.7 python manage.py makemigrations ...

  5. Python安装mysql-python错误提示python setup.py egg_info

    做python项目,需要用到mysql,一般用python-mysql,安装时遇到错误提示如下: Command "python setup.py egg_info" failed ...

  6. python __init__.py用途

    转自http://www.cnpythoner.com/post/2.html Python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时, ...

  7. python setup.py uninstall

    I have installed a python package with python setup.py install How do I uninstall it? ============== ...

  8. python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案

    python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...

  9. Python Web.py

    安装Web.py root@bt:~# sudo pip install web.py Downloading/unpacking web.py Downloading web.py-0.37.tar ...

随机推荐

  1. 针对JS经典题型对全局变量及局部变量的理解浅谈

    第一次写博,还蛮激动... 看到了三题经典题型,就我目前的认识对此题进行总结.如有错误,敬请指正 首先,我们先明确一下JS引擎的工作步骤: js引擎工作分为两步: 1.将这个js中的变量和函数声明保存 ...

  2. Atitit 在线支付系统功能设计原理与解决方案 与目录

    Atitit 在线支付系统功能设计原理与解决方案 与目录 1.1. 支付系统1 1.2. 独立的支付子体系..微服务架构..1 1.3. 参考书籍1 支付战争 [The PayPal Wars:Bat ...

  3. js的replace函数入参为function时的疑问

    近期在写js导出excel文件时运用到replace方法,此处详细的记录下它各个参数所代表的的意义. 定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式 ...

  4. MySQL Performance-Schema(三) 实践篇

    前一篇文章我们分析了Performance-Schema中每个表的用途,以及主要字段的含义,比较侧重于理论的介绍.这篇文章我主要从DBA的角度出发,详细介绍如何通过Performance-Schema ...

  5. 0038 Java学习笔记-多线程-传统线程间通信、Condition、阻塞队列、《疯狂Java讲义 第三版》进程间通信示例代码存在的一个问题

    调用同步锁的wait().notify().notifyAll()进行线程通信 看这个经典的存取款问题,要求两个线程存款,两个线程取款,账户里有余额的时候只能取款,没余额的时候只能存款,存取款金额相同 ...

  6. Nodejs安装

    1 下载NodeJS   https://nodejs.org/download/ 最新版下载地址 # wget https://nodejs.org/dist/v0.12.7/node-v0.12. ...

  7. UC浏览器中touch事件的异常记录

    以前也在UC上面栽过几个坑,不过都是页面显示方面的.上个周的时候,商品详情页重做,要添加个上拉显示详情的效果. 有两个条件需要判断: 1.是否到达底部: 2.到达底部之后拖动的y轴距离. 效果写完后, ...

  8. POJ2104 K-th Number [分块做法]

    传送:主席树做法http://www.cnblogs.com/candy99/p/6160704.html 做那倒带修改的主席树时就发现分块可以做,然后就试了试 思想和教主的魔法差不多,只不过那个是求 ...

  9. 安全测试 - XSS如何防御

    XSS主要是通过劫持用户COOKIE,执行JS脚本进行攻击 如何发现: 可以使用<script>alert(/yourname/)</script> script最具有代表性也 ...

  10. 机器学习之sklearn——聚类

    生成数据集方法:sklearn.datasets.make_blobs(n_samples,n_featurs,centers)可以生成数据集,n_samples表示个数,n_features表示特征 ...