所以,我写了一个端口扫描器,它工作得很好。它输出了我想要的一切。但在某种程度上,我已经打破了它,我无法确定我是如何打破它的。
我得到的错误是:
line 12, in portscan
if(tcp_connect.getlayer(TCP).flags == SYNACK):
AttributeError: 'NoneType' object has no attribute 'getlayer'
[Finished in 4.4s with exit code 1]下面是脚本:
#!/usr/bin/env python3
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
def portscan(host,dst_port):
src_port = RandShort()
SYNACK = 0x12
RSTACK = 0x14
tcp_connect = sr1(IP(dst=host)/TCP(sport=src_port,dport=dst_port,flags="S"),verbose=0,timeout=2)
if(tcp_connect.getlayer(TCP).flags == SYNACK):
send_rst = sr(IP(dst=host)/TCP(sport=src_port,dport=dst_port,flags="AR"),verbose=0,timeout=2)
print (dst_port,"is open")
elif (tcp_connect.getlayer(TCP).flags == RSTACK):
print (dst_port,"is closed")
if __name__ == '__main__':
host = '192.168.0.40'
port = 80
portscan(host,port)我不知道我改变了什么才能打破它。任何想法都将不胜感激!
发布于 2018-06-29 17:15:11
卡西根一人指出:
如果没有响应,则将在到达超时时分配一个None值。没有人被归还,这意味着没有回应。你得检查一下。。。
解决办法:
if tcp_connect == None:
(Handle Failure)
else:
(Handle success)https://stackoverflow.com/questions/51105996
复制相似问题