#!/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. Github装(zao)逼(jia)指(da)南(fa)

    Github之于工程师,类似于微博相册之于嫩模,像是个门面. 无论是晋升答辩,还是求职面试,有一个丰富的代码仓库不敢说好处有多大,但总归是有的.并且好处不局限于此,代码开源才会暴露问题才会改正,并且会 ...

  2. iOS 应用程序生命周期

    开发应用程序都要了解其生命周期. 今天我们接触一下iOS应用程序的生命周期, iOS的入口在main.m文件: int main(int argc, char * argv[]) { @autorel ...

  3. iOS 获取当前点击的坐标

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSSet *allTouch ...

  4. android 自定义控件——(二)圆形按钮,圆形View

    ----------------------------------↓↓圆形按钮,圆形View(源代码下有属性解释)↓↓---------------------------------------- ...

  5. Andriod 自定义控件之创建可以复用的组合控件

    前面已学习了一种自定义控件的实现,是Andriod 自定义控件之音频条,还没学习的同学可以学习下,学习了的同学也要去温习下,一定要自己完全的掌握了,再继续学习,贪多嚼不烂可不是好的学习方法,我们争取学 ...

  6. iOS App 不支持http协议 App Transport Security has blocked a cleartext HTTP (http://)

    目前iOS已经不支持http协议了,不过可以通过info.plist设置允许 App Transport Security has blocked a cleartext HTTP (http://) ...

  7. 做JavaWeb开发不知Java集合类不如归家种地

    Java作为面向对象语言对事物的体现都是以对象的形式,为了方便对多个对象的操作,就要对对象进行存储.但是使用数组存储对象方面具有一些弊端,而Java 集合就像一种容器,可以动态地把多个对象的引用放入容 ...

  8. Java导出excel

    一.介绍 常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统.银行系统).或者是:我们已经习惯用Excel打印.这样在我们实际的开发中,很多时候需要实现导入.导出Excel的应用. ...

  9. [hadoop in Action] 第3章 Hadoop组件

    管理HDFS中的文件 分析MapReduce框架中的组件 读写输入输出数据   1.HDFS文件操作   [命令行方式]   Hadoop的文件命令采取的形式为: hadoop fs -cmd < ...

  10. 错误: “WebForm_DoPostBackWithOptions”未定义

    无论是ASP.NET WebForm 还是 ASP.NET MVC项目,在本地程序测试没问题,但是部署在IIS上访问就会出现  错误: “WebForm_DoPostBackWithOptions”未 ...