代码
1 from scapy.all import IP,TCP,sr 2 ans,unans=sr(IP(dst="192.168.1.128")/TCP(dport=[21,23,135,443,445],flags="A"),timeout=3) 3 for s,r in ans: 4 if s[TCP].dport == r[TCP].sport: 5 print(str(s[TCP].dport)+" is unfiltered") 7 for s in unans: 8 print(str(s[TCP].dport)+" is filtered")
先从scapy模块中导入需要的对象,进行用sr()函数进行扫描,类型为ACK扫描,最后遍历有返回的包和没返回的包,有返回的包表示端口未被过滤,无返回包表示端口已经被过滤