Skip to content

Commit 85c6e4b

Browse files
committed
first_add
1 parent 4ea20ed commit 85c6e4b

File tree

5 files changed

+889
-1
lines changed

5 files changed

+889
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# httpscan
2-
一个爬虫式的网段Web主机发现小工具
2+
httpscan是一个扫描指定网段的Web主机的小工具。和端口扫描器不一样,httpscan是以爬虫的方式进行Web主机发现,因此相对来说不容易被防火墙拦截。
3+
4+
httpscan会返回IP http状态码 Web容器版本 以及网站标题。
5+
![demo][1]
6+
7+
Usage:./httpscan IP/CIDR –t threads
8+
9+
Example:./httpscan.py 10.20.30.0/24 –t 10
10+
11+
12+
[1]: https://raw.githubusercontent.com/zer0h/httpscan/master/log/demo.png

httpscan.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
#coding:utf-8
3+
# Author: Zeroh
4+
5+
import re
6+
import sys
7+
import Queue
8+
import threading
9+
import optparse
10+
import requests
11+
from IPy import IP
12+
13+
printLock = threading.Semaphore(1) #lock Screen print
14+
TimeOut = 5 #request timeout
15+
16+
#User-Agent
17+
header = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36','Connection':'close'}
18+
19+
class scan():
20+
21+
def __init__(self,cidr,threads_num):
22+
self.threads_num = threads_num
23+
self.cidr = IP(cidr)
24+
#build ip queue
25+
self.IPs = Queue.Queue()
26+
for ip in self.cidr:
27+
ip = str(ip)
28+
self.IPs.put(ip)
29+
30+
def request(self):
31+
with threading.Lock():
32+
while self.IPs.qsize() > 0:
33+
ip = self.IPs.get()
34+
try:
35+
r = requests.Session().get('http://'+str(ip),headers=header,timeout=TimeOut)
36+
status = r.status_code
37+
title = re.search(r'<title>(.*)</title>', r.text) #get the title
38+
if title:
39+
title = title.group(1).strip().strip("\r").strip("\n")[:30]
40+
else:
41+
title = "None"
42+
banner = ''
43+
try:
44+
banner += r.headers['Server'][:20] #get the server banner
45+
except:pass
46+
printLock.acquire()
47+
print "|%-16s|%-6s|%-20s|%-30s|" % (ip,status,banner,title)
48+
print "+----------------+------+--------------------+------------------------------+"
49+
50+
#Save log
51+
with open("./log/"+self.cidr.strNormal(3)+".log",'a') as f:
52+
f.write(ip+"\n")
53+
54+
except Exception,e:
55+
printLock.acquire()
56+
finally:
57+
printLock.release()
58+
59+
#Multi thread
60+
def run(self):
61+
for i in range(self.threads_num):
62+
t = threading.Thread(target=self.request)
63+
t.start()
64+
65+
if __name__ == "__main__":
66+
parser = optparse.OptionParser("Usage: %prog [options] target")
67+
parser.add_option("-t", "--thread", dest = "threads_num",
68+
default = 10, type = "int",
69+
help = "[optional]number of theads,default=10")
70+
(options, args) = parser.parse_args()
71+
if len(args) < 1:
72+
parser.print_help()
73+
sys.exit(0)
74+
75+
print "+----------------+------+--------------------+------------------------------+"
76+
print "| IP |Status| Server | Title |"
77+
print "+----------------+------+--------------------+------------------------------+"
78+
79+
s = scan(cidr=args[0],threads_num=options.threads_num)
80+
s.run()

0 commit comments

Comments
 (0)