python端口遍历

【python端口遍历】#coding=utf-8import socketimport datetime#ip='192.168.1.2'ip=str(input('请输入对应的ip地址:'))prot1=int(input('请输入对应的起始端口:'))prot2=int(input('请输入对应的结束端口:'))#判断端口if prot1>prot2 and prot1<65535:print('端口输入错误,起始端口需要小于结束端口')#判断ip#if re.match('')#创建遍历文件c_text=ip.replace('.','-')t_log = str(datetime.date.today())ts_log=c_text+'检测时间'+t_log+'.txt'#端口扫描1~65535with open(ts_log,'a+') as f:f.write("检测时间")f.write(t_log)f.write("")f.write("检测ip")f.write(ip)f.write('n')port = 1while prot1<=prot2:# 具体时间dada = str(datetime.datetime.now())# 具体日期print('即将扫描',ip,'-',port)# 端口检查s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)# connect_ex正常返回0,不正常返回10061cc = s.connect_ex((ip, port))#创建ip+date时间文件if cc == 0:f.write(dada)f.write("")f.write(ip)f.write("")f.write(str(port))f.write("")f.write("端口连接正常")f.write('n')s.shutdown(socket.SHUT_RDWR)else:f.write(str(dada))f.write("")f.write(ip)f.write("")f.write(str(port))f.write("")f.write("端口连接失败")f.write('n')s.close()prot1=prot1+1#欢迎大家关注改正,我们一起进步你会Python吗单选

不会
还有 6 天 7 小时结束 





    推荐阅读