一个简易的端口扫描器
本帖最后由 xiaoye 于 2015-9-30 10:48 编辑支持批量和扫描单一的主机,端口需要自己添加常用端口
import IPy
import threading
import Queue
import time
import socket
import optparse
import sys
reload(sys)
sys.setdefaultencoding("utf8")
queue=Queue.Queue()
ports=
########################################################################
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 |www.isbug.net +
+------------------------------------+
'''
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!"
支持中国红客联盟(ihonker.org) 感谢楼主的分享~ 学习学习技术,加油! 感谢楼主的分享~ 学习学习技术,加油! 支持,看起来不错呢! 学习学习技术,加油! 还是不错的哦,顶了