Trying to write a script that performs ARP scanning of the local network. With the help of Google, I wrote the following code: (here, the Range is set to the type "192.168.0.0/24")

import sys import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import srp, Ether, ARP, conf def scan(Range): conf.verb = 0; alive,dead = srp(Ether(dst = "ff:ff:ff:ff:ff:ff") / ARP( pdst = Range ), timeout = 2, verbose = 0) return alive 

But there were 3 problems:

1) The script does not work if I connected to the network via WiFi.

2) I need to support 2 ways to set the scan range:

(192.168.0.0/24) or (192.168.0.1 - 192.168.0.255). I was able to implement only the first.

3) Scanning results are unstable, can find 2, can find 4 hosts with unchanged network status, what can this be connected with?

How can I do what I need? In Python newbie.

  • 1- Try to limit yourself to only one problem in each Stack Overflow question (so that not only the question would be useful to you). If you need to ask a few independent questions 2- On what network interface do you expect this code sends packets? Which wifi interface works? What output arp utility shows? What time is your arp cache stored? What is OS? 3- Why don't you use arping ()? - jfs
  • This code sends packets over Ethernet, but I have no idea how to send packets over WiFi, because there are a lot of functions connected with it in the same scapy. The arp utility shows the following output: 192.168.0.1 c4-6e-1f-cb-84-a4 192.168.0.100 08-d4-0c-c5-86-45 192.168.0.103 80-e6-50-46-e7-53 192.168. 0.255 ff-ff-ff-ff-ff-ff While my code finds from 1 to 2 random hosts from this list. OS - Windiws 10 x64 - Timur Yalimov
  • Which wifi interface works? - Could not figure out what time is your arp cache stored? - Couldn't figure out Why don't you use arping ()? - arping () returns the same behavior, in fact my code is partly taken from its implementation - Timur Yalimov
  • Your code gets answers if the iface parameter iface correct on my machine (and does not receive if it is incorrect). If you do not know "how to get a list of network interfaces on Windows" ask a separate question. Start with get_if_list() . - jfs

0