from scapy.all import ARP, Ether, srp def scan_network(ip_range): # 1. Create an ARP request packet arp = ARP(pdst=ip_range) # 2. Create an Ethernet broadcast packet ether = Ether(dst="ff:ff:ff:ff:ff:ff") # 3. Stack them together packet = ether/arp # 4. Send the packet and capture the response result = srp(packet, timeout=3, verbose=0)[0] # 5. Parse the results clients = [] for sent, received in result: clients.append({'ip': received.psrc, 'mac': received.hwsrc}) return clients # Example usage: # devices = scan_network("192.168.1.1/24")