简单的C段探测Title+Server
用法 python xx.py --url xx.xx.x.x
效果图如下...
#-*- coding:utf-8 -*-import reimport requestsimport sys#隐蔽https请求报错requests.packages.urllib3.disable_warnings()def c(ip):
'''
生成c段以及请求c段
'''
reg = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.'
a = re.findall(reg,ip)
ip_list = [] #生成c段ip
for i in range(1,256):
ip_list.append(a[0]+repr(i))
headers = { 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'
}
for i in ip_list: try:
response = requests.get('http://'+i,verify=False,headers=headers,timeout=5)
titles(i,response) except Exception,e: print ' 【IP】:http://'+i+' 请求失败'def titles(i,response):
'''
处理输出信息
'''
reg = r'<title>(.*?)</title>'
title = re.findall(reg,response.content.lower()) if(response.headers['server'] != ''):
server = response.headers['server'] else:
server = 'Null'
print ' 【IP】:http://'+i, if(len(title) != 0): print ' Server:'+server, print ' Title:',
try: print title[0].decode('utf-8') except Exception,e: print title[0].decode('gbk') else: print ' Server:'+serverif(len(sys.argv) < 3):
sys.exit('参数有误,正确格式为:scan.py --url xx.xx.xx.xx')else:
ip = sys.argv[2]
reg = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'ip_get = re.findall(reg,ip)if(len(ip_get) == 0):
sys.exit('IP有误,正确格式为:scan.py --url xx.xx.xx.xx')else:
c(ip_get[0])