下面是一个简单的端口扫描程序,非常菜鸟级别的入门脚本,程序中只针对本机端口进行理论扫描,未设置条件判断和其它信息回显,属于基础Python:
import socket
for port in range(20,1024):
try:
s = socket.socket()
print " [+] Attempting to connect to 127.0.0.1 : " + str(port)
s.connect(('127.0.0.1',port))
s.send('myscan')
banner = s.recv(1024)
if banner:
print " [+] Port " + str(port) + " open: \n" + banner
s.close()
except:pass