博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python gettitle.py
阅读量:5750 次
发布时间:2019-06-18

本文共 5127 字,大约阅读时间需要 17 分钟。

#!/usr/bin/env python# coding=utf-8import threadingimport requestsimport Queueimport sysimport reimport timeimport warningsimport datetimeimport argparse__author__ = 'depycode'warnings.filterwarnings("ignore")#ip to numdef ip2num(ip):    ip = [int(x) for x in ip.split('.')]    return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3]#num to ipdef 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 threadclass 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:                continuedef 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'(.*?)',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:            passdef 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_adef report(data):    t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))    f = open('Title'+'-'+str(t)+".html","w+")    table1 = "
\n
\n" f.write(table1) for i in data: rows = "
\n" %(i['aimurl'],i['ip']+":"+i['port'],i['status'],i['server'],i['title']) f.write(rows) table2 = "
url stauts_code server title
%s %s %s %s
" 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::depycodeoptional 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

转载于:https://www.cnblogs.com/depycode/p/5486537.html

你可能感兴趣的文章
我的友情链接
查看>>
Windows Phone 7 隔离存储空间资源管理器
查看>>
apache安装报错undefined reference ssl
查看>>
关于爱情只有一句忠告
查看>>
CentOS 7下安装部署Oracle11g图文教程
查看>>
F#初学笔记06
查看>>
实战:将企业域名解析委派给企业DNS服务器
查看>>
在Lync 2013环境部署Office Web Apps
查看>>
微软大会Ignite,你准备好了么?
查看>>
读书笔记-高标管事 低调管人
查看>>
Master带给世界的思考:是“失控”还是进化
查看>>
用户和开发者不满苹果iCloud问题多多
查看>>
java.lang.UnsatisfiedLinkError:no dll in java.library.path终极解决之道
查看>>
我的工具:文本转音频文件
查看>>
【许晓笛】从零开始运行EOS系统
查看>>
【跃迁之路】【460天】程序员高效学习方法论探索系列(实验阶段217-2018.05.11)...
查看>>
C++入门读物推荐
查看>>
TiDB 源码阅读系列文章(七)基于规则的优化
查看>>
Spring之旅第八站:Spring MVC Spittr舞台的搭建、基本的控制器、请求的输入、表单验证、测试(重点)...
查看>>
数据结构与算法——常用排序算法及其Java实现
查看>>