准备
- socket
- sys
- port1000.txt
import socket
import sys
#Usage: python3 portscan.py x.x.x.x
#输入目标ip
ip = sys.argv[1]
#SOCKE_STREAM:tcp AF_INET:ipv4
with open('port1000.txt','r') as f:
for i in f:
i = i.strip()
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(1)
a = s.connect((ip,int(i)))
if a == None:
print("\033[1;32;40m %s \033[0m" % (ip+' open:'+i))
s.close()
else:
s.close()
continue
except Exception as e:
pass
f.close()
运行效果:
未完待续
差多线程,超时时间1秒,1000个端口跑到猴年马月,而且还是tcp连接,特别容易被检测到,回头再撸一个多线程版本