0

hello i am trying to make an app that shows all the connected devices to the network how can write the range from 192.168.0.1 to 192.168.0.255 in CIDR notation ? enter image description here

Esra Issam
  • 17
  • 5
  • 2
    Possible duplicate of https://stackoverflow.com/questions/24214441/ip-range-to-cidr-conversion-in-python – SNygard Jul 14 '22 at 17:00
  • Hi Esra, welcome to StackOverflow. Please include any code that you've tried already and the errors that you're encountering. – SNygard Jul 14 '22 at 17:01
  • all right, I will edit the post please check it – Esra Issam Jul 14 '22 at 17:28
  • 1
    Does this answer your question? [IP Range to CIDR conversion in Python?](https://stackoverflow.com/questions/24214441/ip-range-to-cidr-conversion-in-python) – RobinFrcd Jul 14 '22 at 17:32

1 Answers1

0

Scapy understands CIDR notation in IP address fields by automatically converting it to a Net object:

>>> import scapy.all as scapy
>>> scapy.Net("192.168.0.1/24")
Net("192.168.0.1/24")
>>> list(_)
['192.168.0.0',
 '192.168.0.1',
 '192.168.0.2',
 '192.168.0.3',
 ...

but in your example you can just do

>>> eth = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
>>> arp = scapy.ARP(pdst="192.168.0.1/24")
>>> scapy.srp(eth / arp, timeout=5)[0]

since, as I said, it's converted behind the scenes.

Cukic0d
  • 5,111
  • 2
  • 19
  • 48