Advertisement
rfmonk

scapy_tcp_scan.py

May 10th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/opt/local/bin/python
  2.  
  3.  
  4. import logging
  5. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  6. from scapy import *
  7.  
  8. dst_ip = "5.0.173.19"
  9. src_port = RandShort()
  10. dst_port = 80  
  11.  
  12. tcp_connect_scan_resp = sr1(IP(dst=dst_ip)/TCP \
  13.     (sport=src_port,dport=dst_port,flags="S"),timeout=10)
  14.  
  15. if(str(type(tcp_connect_scan_resp)) == "<type 'NoneType'>"):
  16.     print "closed"
  17.  
  18. elif(tcp_connect_scan_resp.haslayer(TCP)):
  19.     if(tcp_connect_scan_resp.getlayer(TCP).flags == 0x12):
  20.         send_rst = sr(IP(dst=dst_ip)/TCP \
  21.             (sport=src_port,dport=dst_port,flags="AR"),timeout=10)
  22.         print "open"
  23.     elif(tcp_connect_scan_resp.getlayer(TCP).flags == 0x14):
  24.         print "closed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement