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

1.9k Views Asked by At

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
2

There are 2 best solutions below

1
Kunal Sikri On BEST ANSWER

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")
0
Ross Jacobs On

Use scapy's built-in arping instead to do an ARP scan:

from scapy.all import arping

arping("192.168.1.0/24")

Then in your shell:

$ python3 arping.py
Begin emission:
*****************Finished sending 256 packets.

Received 17 packets, got 17 answers, remaining 239 packets
  00:1b:78:20:ee:40 192.168.1.48
  a4:77:33:88:92:62 192.168.1.66
  6c:33:a9:42:6a:18 192.168.1.67
...

Arping docs are here.