python编写简单端口扫描器
人气:0直接放代码
此代码只支持扫描域名,要扫描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()
运行代码
代码执行结果
因为代码过于简单,这里我就不具体解释了。
您可能感兴趣的文章:
加载全部内容