Search code snippets, questions, articles...

Function to scan devices in the network using the ARP protocol

from scapy.all import *

def scan(ip_router):
    ether = Ether(dst='ff:ff:ff:ff:ff:ff')
    ip_range = f'{ip_router}/24'
    arp = ARP(pdst=f'{IP_ROUTER}/24')
    request = ether / arp
    ans, unans = srp(request, timeout=2, verbose=False, retry=1)
    data = dict()
    for sent, reciverd in ans:
        data[reciverd.psrc] =  reciverd.hwsrc
    return data
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet