1
我編寫了一個端口掃描程序來了解更多關於網絡的信息
但由於某些原因,它只會爲每個掃描的端口返回port n is closed
。python scapy portscanner的問題
import sys
from scapy.all import *
target = str(sys.argv[1])
beg = int(sys.argv[2])
ran = int(sys.argv[3])
ptable = []
print "beginning port scan on target: " + target
for x in range(beg,ran):
pkt = IP(dst=target)/TCP(dport=x,flags="S")
ans,uans = sr(pkt,timeout=0.5)
if TCP in ans:
if ans[TCP].flags == "SA":
ptable.append(1)
else:
ptable.append(0)
print "======================== port scan summary ==========================="
print " "
for i in range(beg,ran):
if ptable[i-1] == 1:
print "port " + str(i) + " is open"
else:
print "port " + str(i) + " is closed"
在第一個'for'循環中添加'print'來查看'ans [TCP] .flags'的結果 – furas