python gettitle.py
#!/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的更多相关文章
- python gettitle v2.0
#!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...
- python调用py中rar的路径问题。
1.python调用py,在py中的os.getcwd()获取的不是py的路径,可以通过os.path.split(os.path.realpath(__file__))[0]来获取py的路径. 2. ...
- Python pydoc.py
1. 查看帮助,我们可以在python命令行交互环境下用 help函数,比如: 查看 math 模块: >>> help('math')Help on built-in module ...
- django 1.7之后python manage.py syncdb没有了
在命令行输入python manage.py createsuperuser按照提示输入即可记得先初始化表. django>1.7 python manage.py makemigrations ...
- Python安装mysql-python错误提示python setup.py egg_info
做python项目,需要用到mysql,一般用python-mysql,安装时遇到错误提示如下: Command "python setup.py egg_info" failed ...
- python __init__.py用途
转自http://www.cnpythoner.com/post/2.html Python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时, ...
- python setup.py uninstall
I have installed a python package with python setup.py install How do I uninstall it? ============== ...
- python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案
python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...
- Python Web.py
安装Web.py root@bt:~# sudo pip install web.py Downloading/unpacking web.py Downloading web.py-0.37.tar ...
随机推荐
- LinQ to SQL用法详解
LinQ是指集成化查询语言,通过映射将数据库内的表名变为C#的类名,将列名作为属性名,将表的关系作为类的成员对象.O--M--R O-Object对象(李昌辉)R-Relation关系M-Mappin ...
- ThinkPHP 整合Bootstrap Ajax分页
ThinkPHP Ajax分页代码 publicfunction index() { $where=array(); $name = I('name'); if(!empty($name)){ $wh ...
- jquery 点击查看更多箭头变化,文字变化,超出带滚动条。
从网上好了好久,没找到自己要的,自己写了一下. <!DOCTYPE html> <html> <head> <meta charset="utf-8 ...
- DevExpress VCL v16.1.3发布
ExpressPDFViewer # BC3840:包含action标题和action提示的 Action classes 和 resource strings 重命名: class名称末尾中包含'A ...
- Hibernate 系列 02 - Hibernate介绍及其环境搭建
引导目录: Hibernate 系列教程 目录 昨晚喝多了,下午刚清醒,继续搞Hibernate.走起. 觉得还行的话,记得点赞哈,给我这个渣渣点学习的动力.有错误的话也请指出,省的我在错误上走了不归 ...
- [AlwaysOn Availability Groups]使用Powershell监控AlwayOn健康
使用Powershell监控AlwayOn健康 1.基本命令概述 AlwayOn Dashboard是很有用的查看整体AG健康状况的工具.但是这个工具不是用于7*24监控的.如果应用程序夜间发送严重的 ...
- ubuntu关于引导修复[grub命令行][live linux]
第一种:grub命令行: ls 列出所有分区 ls /grub ls /grub 检查确认linux引导分区,如果linux单独/boot分区,就要采用如下命令进行检查: ls /boot/grub ...
- android 关闭多个或指定activity
打开了.activityA,B,C,D,...然后到E一起关闭前面所有activity(转自:http://blog.csdn.net/lengguoxing/article/details/4214 ...
- CFD冲蚀模拟的一些理论
[TOC] 在CFD中计算颗粒对固体壁面的冲蚀往往采用冲蚀模型(Erosion Model). 1 冲蚀速率(Erosion Rate) 冲蚀速率定义为壁面材料在单位时间单位面积上损失的质量(单位:\ ...
- 如何配置远程mysql服务器
如何配置远程mysql服务器 分配用户权限 可以先看一下目前的用户权限状况: use mysql; select host,user,password from user; 然后分配新的权限给某一用户 ...