python编写简单端口扫描器
本文实例为大家分享了python编写简单端口扫描器的具体代码,供大家参考,具体内容如下
直接放代码
此代码只支持扫描域名,要扫描IP请自己修改
from socket import * from threading import Thread import optparse Port = [80,21,23,22,25,110,443,1080,3306,3389,1521,1433] Server = ['HTTP','FTP','TELNET','SSH','SMTP','POP3','HTTPS','SOCKS','MYSQL','Misrosoft RDP','Oracle','Sql Server'] def Scan(tghost,tgport,Server): try: s=socket() s.connect((tghost,tgport)) print(tghost+'____>'+str(tgport)+' open',end='||||| ') print(str(tgport)+'---->'+Server) s.close() except: print(str(tgport)+'----> '+'not open') def hostToaddr(host):#将域名转成ip try: return gethostbyname(host) except: return def main(): parser=optparse.OptionParser() parser.add_option('-t', dest='dname') #parser.add_option('-p',dest='pname') (options,args)=parser.parse_args() if(options.dname==None): print('[-] You must specify a target host and port') exit(0) else: tgname=options.dname ip=hostToaddr(tgname) #Scan(ip) for i,j in zip(Port,Server):#用线程提高速度 t=Thread(target=Scan,args=(ip,i,j)) t.start() input()#cmd界面如果快速闪退,请加入这条代码 if __name__=='__main__': main()
运行代码
代码执行结果
因为代码过于简单,这里我就不具体解释了。
相关推荐
huavhuahua 2020-11-20
weiiron 2020-11-16
cakecc00 2020-11-15
千锋 2020-11-15
JakobHu 2020-11-14
guangcheng 2020-11-13
xirongxudlut 2020-11-10
solarLan 2020-11-09
pythonxuexi 2020-11-08
文山羊 2020-11-07
susmote 2020-11-07
wuShiJingZuo 2020-11-05
Pythonjeff远 2020-11-06
jacktangj 2020-11-04
lousir 2020-11-04
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17