11#!/usr/bin/env python
22#coding:utf-8
33# Author: Zeroh
4+ # Modified: Cobranail
45
56import re
67import sys
1112from IPy import IP
1213
1314printLock = 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
1718header = {'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
1920class 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