Skip to content

Commit 17a309b

Browse files
committed
Add support for ports scan
1 parent 28c7bd7 commit 17a309b

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ httpscan是一个扫描指定CIDR网段的Web主机的小工具。和端口扫
44
httpscan会返回IP http状态码 Web容器版本 以及网站标题。
55
![demo][1]
66

7-
**Usage**`./httpscan IP/CIDR –t threads`
7+
**Usage**`./httpscan IP/CIDR –t threads -p ports`
88

9-
Example:`./httpscan.py 10.20.30.0/24 –t 10`
9+
Example:`./httpscan.py 10.20.30.0/24 –t 10 -ports 80,8080-8090`
1010

1111

1212
[1]: https://raw.githubusercontent.com/zer0h/httpscan/master/log/demo.png

httpscan.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
#coding:utf-8
33
# Author: Zeroh
4+
# Modified: Cobranail
45

56
import re
67
import sys
@@ -11,26 +12,43 @@
1112
from IPy import IP
1213

1314
printLock = threading.Semaphore(1) #lock Screen print
14-
TimeOut = 5 #request timeout
15+
TimeOut = (0.5,1) #request timeout, for slow connection
1516

1617
#User-Agent
1718
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'}
1819

1920
class scan():
2021

21-
def __init__(self,cidr,threads_num):
22+
def __init__(self,cidr, threads_num, ports):
2223
self.threads_num = threads_num
24+
self.ports=[]
25+
ports_set=[]
26+
if ',' in ports:
27+
ports_set=ports.split(',')
28+
else:
29+
ports_set=[ports]
30+
#print ports_set
31+
for ps in ports_set:
32+
if '-' in ps:
33+
pp = ps.split('-')
34+
self.ports = self.ports+range(int(pp[0]),int(pp[1])+1)
35+
else:
36+
self.ports.append(ps)
37+
#print self.ports
2338
self.cidr = IP(cidr)
2439
#build ip queue
2540
self.IPs = Queue.Queue()
2641
for ip in self.cidr:
27-
ip = str(ip)
28-
self.IPs.put(ip)
42+
for port in self.ports:
43+
ipp = str(ip)+':'+str(port)
44+
#print ipp
45+
self.IPs.put(ipp)
2946

3047
def request(self):
3148
with threading.Lock():
3249
while self.IPs.qsize() > 0:
3350
ip = self.IPs.get()
51+
#print str(ip)
3452
try:
3553
r = requests.Session().get('http://'+str(ip),headers=header,timeout=TimeOut)
3654
status = r.status_code
@@ -44,8 +62,8 @@ def request(self):
4462
banner += r.headers['Server'][:20] #get the server banner
4563
except:pass
4664
printLock.acquire()
47-
print "|%-16s|%-6s|%-20s|%-30s|" % (ip,status,banner,title)
48-
print "+----------------+------+--------------------+------------------------------+"
65+
print "|%-24s|%-6s|%-20s|%-30s|" % (ip,status,banner,title)
66+
print "+------------------------+------+--------------------+------------------------------+"
4967

5068
#Save log
5169
with open("./log/"+self.cidr.strNormal(3)+".log",'a') as f:
@@ -67,14 +85,17 @@ def run(self):
6785
parser.add_option("-t", "--thread", dest = "threads_num",
6886
default = 10, type = "int",
6987
help = "[optional]number of theads,default=10")
88+
parser.add_option("-p", "--ports", dest = "ports",
89+
default = '80', type = "string",
90+
help = "[optional]number of theads,default=10")
7091
(options, args) = parser.parse_args()
7192
if len(args) < 1:
7293
parser.print_help()
7394
sys.exit(0)
7495

75-
print "+----------------+------+--------------------+------------------------------+"
76-
print "| IP |Status| Server | Title |"
77-
print "+----------------+------+--------------------+------------------------------+"
96+
print "+------------------------+------+--------------------+------------------------------+"
97+
print "| IP |Status| Server | Title |"
98+
print "+------------------------+------+--------------------+------------------------------+"
7899

79-
s = scan(cidr=args[0],threads_num=options.threads_num)
100+
s = scan(cidr=args[0],threads_num=options.threads_num, ports=options.ports)
80101
s.run()

0 commit comments

Comments
 (0)