Search code examples
pythonpython-3.xscapyarpnetwork-scan

scapy.srp() doesn't responds with expected result


I am trying to code of network scanner and further once I try to print the response, it does not show anything.

import scapy.all as scapy


def scan(ip):
    packet1 = scapy.ARP(pdst=ip)
    etherpacket = scapy.Ether(dst = 'ff:ff:ff:ff:ff:ff')

    broadcast_packet = etherpacket/packet1
    ans, unans = scapy.srp(broadcast_packet, timeout=10)

    print(ans.summary())





scan("192.168.1.1-254")

Below is the result.

$sudo python3 networkscanner.py 
Begin emission:
........Finished sending 1 packets.
..........
Received 18 packets, got 0 answers, remaining 1 packets
None

Solution

  • The change shall be in when the function is called, it should be /24 not the way written above.

    import scapy.all as scapy
    
    
        def scan(ip):
            packet1 = scapy.ARP(pdst=ip)
            etherpacket = scapy.Ether(dst = 'ff:ff:ff:ff:ff:ff')
    
            broadcast_packet = etherpacket/packet1
            ans, unans = scapy.srp(broadcast_packet, timeout=10)
    
            print(ans.summary())
    
    
    
    
    
        scan("192.168.1.1/24")