Boomer101

network_scanner.py

Nov 7th, 2020
46
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import scapy.all as scapy
  4.  
  5. def scan(ip):
  6. arp_request = scapy.ARP(pdst=ip)
  7. broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
  8. arp_request_broadcast = broadcast/arp_request
  9. answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False) [0]
  10.  
  11. clients_list = []
  12. for element in answered_list:
  13. client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
  14. clients_list.append(client_dict)
  15. return(clients_list)
  16.  
  17. def print_result(results_list):
  18. print("IP\t\t\tMAC Address\n----------------------")
  19. for client in results_list:
  20. print(client["ip"] + "\t\t" + client["mac"])
  21.  
  22.  
  23. scan_result = scan("10.0.2.1/24")
  24. print_result(scan_result)
  25.  
RAW Paste Data