1

My code is suppose to send packets and get the mac address back but i get some error, The code:

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    print(arp_request_broadcast.summary())

scan("10.0.2.1/24")

The error is:

Ether / ARP who has ?? says ??
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Beast
  • 43
  • 1
  • 8

1 Answers1

0

The value you passed to the layer ARP is just fine. But your code is not sending/receiving any packets to the network.

let's fix your code:


from scapy.all import ARP, Ether, srp
import scapy.all as scapy

def scan(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request

    # send packet to the network, wait for replies for 3 secondes, then return all the answers
    result = srp(arp_request_broadcast, timeout=3, verbose=0)[0]
    
    # for each replay, 
    for sent, received in result:
        print(received.summary())

scan("192.168.1.1/24")

gives me that in my network:

Ether / ARP is at 00:24:46:03:87:11 says 192.168.1.195 / Padding
Ether / ARP is at f8:75:a4:76:68:36 says 192.168.1.216 / Padding
Ether / ARP is at 78:96:84:9c:13:20 says 192.168.1.254 / Padding

note that you need to run that code in sudo, because it needs to read/write to the network

you can see the complete solution here: https://www.thepythoncode.com/article/building-network-scanner-using-scapy

fgagnaire
  • 839
  • 9
  • 18