本帖最后由 xiaoye 于 2015-9-30 10:48 编辑
支持批量和扫描单一的主机,端口需要自己添加常用端口
[Python] 纯文本查看 复制代码 import IPy
import threading
import Queue
import time
import socket
import optparse
import sys
reload(sys)
sys.setdefaultencoding("utf8")
queue=Queue.Queue()
ports=[80,3389]
########################################################################
class IPnum(threading.Thread):
""""""
#----------------------------------------------------------------------
def __init__(self,queue):
"""Constructor"""
threading.Thread.__init__(self)
self.queue=queue
#----------------------------------------------------------------------
def run(self):
""""""
while True:
host,port=self.queue.get()
target=host.__str__()
try:
# print (target,port)
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((target,port))
print "IP:%s\t\tPort:%s\n"%(host,port)
except Exception,e:
pass
finally:s.close()
time.sleep(0.000000001)
self.queue.task_done()
def main(x):
for num in range(20):
t=IPnum(queue)
t.setDaemon(True)
t.start()
ips=IPy.IP(x)
for x in ips:
for port1 in ports:
queue.put((x,port1))
queue.join()
def target(x):
for num in range(20):
t=IPnum(queue)
t.setDaemon(True)
t.start()
for port1 in ports:
queue.put((x,port1))
queue.join()
if __name__=='__main__':
print r'''
+------------------------------------+
+ Author |王珂 +
+------------------------------------+
+ blog |[url]www.isbug.net[/url] +
+------------------------------------+
'''
option=optparse.OptionParser()
option.add_option('-t',dest='target',default='')
option.add_option('-s',dest='host',default='')
(options, args) = option.parse_args()
if not options.target=='':
target(options.target)
if not options.host=='':
main(x)
else :
print "please input target!"
|