http_banner获取v0.2
2015-10-05 09:59
525 查看
#-*-coding=utf-8-*- # __author__ = 'sanr' # __email__ = '5754190@qq.com' # __url__ = 'http://0x007.blog.51cto.com/' # __version__ = '0.2' import requests import re from threading import Thread,Lock import time import sys import chardet import netaddr import struct import socket lock = Lock() def ip2int(addr): return struct.unpack("!I", socket.inet_aton(addr))[0] def int2ip(addr): return socket.inet_ntoa(struct.pack("!I", addr)) def int_dec(pagehtml): charset = None if pagehtml != '': # print 'use charset dect' enc = chardet.detect(pagehtml) # print 'enc= ', enc if enc['encoding'] and enc['confidence'] > 0.9: charset = enc['encoding'] if charset == None: charset_re = re.compile("((^|;)\s*charset\s*=)([^\"']*)", re.M) charset=charset_re.search(pagehtml[:1000]) charset=charset and charset.group(3) or None # test charset try: if charset: unicode('test',charset,errors='replace') except Exception,e: print 'Exception',e charset = None # print 'charset=', charset return charset def http_banner(url): ip=url try: url=requests.get(url,timeout=2) body = url.content charset = None if body != '': charset = int_dec(body) if charset == None or charset == 'ascii': charset = 'ISO-8859-1' if charset and charset != 'ascii' and charset != 'unicode': try: body = unicode(body,charset,errors='replace') except Exception, e: body = '' Struts=url.status_code Server=url.headers['server'][0:13] if Struts==200 or Struts==403 or Struts==401: title=re.findall(r"<title>(.*)<\/title>",body) if len(title): title = title[0].strip() else: title = '' lock.acquire() print ('%s\t%d\t%-10s\t%s'%(ip.lstrip('http://'),Struts,Server,title)) lock.release() except (requests.HTTPError,requests.RequestException,AttributeError,KeyError),e: pass if __name__ == '__main__': if len(sys.argv) >= 2: ips = sys.argv[1] else: print 'usage: python http_banner.py 192.168.1./24 ' print 'usage: python http_banner.py 192.168.1.1-192.168.1.254 ' print 'usage: python http_banner.py 192.168.1./24 8080' print 'usage: python http_banner.py 192.168.1.1-192.168.1.254 8080' sys.exit() port = '80' if len(sys.argv) == 3: port = sys.argv[2] if '-' in ips: start, end = ips.split('-') startlong = ip2int(start) endlong = ip2int(end) ips = netaddr.IPRange(start,end) for ip in list(ips): url='http://%s:%s'%(ip,port) t = Thread(target=http_banner,args=(url,)) t.daemon=False t.start() elif '/' in ips: ips = netaddr.IPNetwork(ips) for ip in list(ips): url='http://%s:%s'%(ip,port) t = Thread(target=http_banner,args=(url,)) t.daemon=False t.start()更新了端口自定义 默认端口为80
本文出自 “Sanr” 博客,请务必保留此出处http://0x007.blog.51cto.com/6330498/1700210
相关文章推荐
- [python] 专题七.网络编程之套接字Socket、TCP和UDP通信实例
- java高薪之路__009_网络
- 《TCP/IP详解 卷一:协议》读书笔记--Ping程序
- HTTPS和SSL/TLS协议
- The Greate Wall 相关网络知识(一)域名劫持
- (中等) Hiho 1232 Couple Trees(15年北京网络赛F题),主席树+树链剖分。
- HTTP error Code
- HTTP协议--超文本传输协议
- TCP/IP 协议栈及 OSI 参考模型详解
- firefox插件-httpRequester-模拟ht…
- httpreques\Json-Handle
- HttpClient的应用1
- HTTPS是如何保证连接安全
- Nginx 的 TCP 负载均衡介绍
- Linux下的socket编程实践(四)TCP服务端优化和常见函数
- TCP/IP详解卷1:第十二章 广播和组播
- HTTP摘要认证方式分析与验证
- 网络编程 学习参考的几个链接
- UVA 12534 - Binary Matrix 2 (网络流‘最小费用最大流’ZKW)
- TCP/IP协议面试常见题目