Advertisement
Yonka2019

question1.py

May 24th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from scapy.all import *
  2. from scapy.layers.dns import DNS, DNSRR
  3. from scapy.layers.inet import IP
  4.  
  5.  
  6. def main():
  7.     KEYS = {"1": dns_selected}
  8.     print_menu()
  9.     KEYS[input("> ")]()
  10.  
  11.  
  12. def dns_selected():
  13.     print("Sniffing: DNS")
  14.     sniff(lfilter=is_dns_answer, prn=print_dns)
  15.  
  16.  
  17. def is_dns_answer(inc_packet):
  18.     my_ip = get_if_addr(conf.iface)
  19.     return DNS in inc_packet and IP in inc_packet and inc_packet[IP].src != my_ip and DNSRR in inc_packet
  20.  
  21.  
  22. def print_dns(inc_packet):
  23.     ip = inc_packet[DNS][DNSRR].rdata
  24.     domain = inc_packet[DNS][DNSRR].rrname
  25.  
  26.     if isinstance(ip, bytes):
  27.         ip = ip.decode()
  28.     if isinstance(domain, bytes):
  29.         domain = domain.decode()
  30.  
  31.     print("########\n"
  32.           f"- ip: {ip}\n"
  33.           f"- domain: {domain}")
  34.  
  35.  
  36. def print_menu():
  37.     print("""
  38. - [MENU] Select by the digit [MENU] -
  39. 1. Print addresses that returned from DNS server
  40. 2. Print weather client response
  41. 3. Print GET link
  42. - [MENU] Select by the digit [MENU] -
  43.    """)
  44.  
  45.  
  46. if __name__ == '__main__':
  47.     main()
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement