So, I wrote a portscanner which worked wonderfully. It outputted everything I wanted. But at some point, I've broken it and I can't identify how I broke it.
The error I'm getting is:
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]
Here is the script:
#!/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)
I'm not sure what I've changed in order for me to break it. Any ideas would be appreciated!
tcp_connectisNone. Have you done any debugging?sr1returnsNone. IS that one of your functions?Nonebeing returned means there was no response. You'll need to check for that. Side Note: Scapy has to have some of the worst docs I've seen. I can't even find a function-by-function breakdown.if(str(type(tcp_connect_scan_resp))=="<type 'NoneType'>"): print ('dead')This is a method I've seen online but it doesn't seem to work for me yet