0

I am trying to build a Networkscanner that scans my localnetwork. Here is how I would do it:

  • Create an ARP Request.
  • Create an Ethernet Frame.
  • Place the ARP Request inside the Ethernet Frame.
  • Send the combined frame and receive responses.
  • Then parse the responses and print the results.

Here is my code so far:

#!/usr/bin/env python3
import scapy.all as scapy

IP = 'here i would enter my IP adress'

def scan(ip):
    arp_packet = scapy.ARP(pdst=ip)
    broadcast_packet = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')
    arp_broadcast_packet = broadcast_packet/arp_packet
    scapy.srp(arp_broadcast_packet, timeout = 1, verbose = False)

scan(IP)

However I am getting the error message :
AttributeError: 'L2bpfSocket' object has no attribute 'ins'

Here is the complete message:

Traceback (most recent call last):
 File "/Users/Uni/Dropbox/Mein Mac (Elias MacBook Pro)/Desktop/wifi2.py", line 12, in <module>
   scan(IP)
 File "/Users/Uni/Dropbox/Mein Mac (Elias MacBook Pro)/Desktop/wifi2.py", line 10, in scan
   scapy.srp(arp_broadcast_packet, timeout = 1, verbose = False)
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/sendrecv.py", line 552, in srp
   s = conf.L2socket(promisc=promisc, iface=iface,
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 242, in __init__
   super(L2bpfListenSocket, self).__init__(*args, **kwargs)
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 62, in __init__
   (self.ins, self.dev_bpf) = get_dev_bpf()
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/core.py", line 114, in get_dev_bpf
   raise Scapy_Exception("No /dev/bpf handle is available !")
scapy.error.Scapy_Exception: No /dev/bpf handle is available !
Exception ignored in: <function _L2bpfSocket.__del__ at 0x7fc3220493a0>
Traceback (most recent call last):
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 139, in __del__
   self.close()
 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/arch/bpf/supersocket.py", line 211, in close
   if not self.closed and self.ins is not None:
AttributeError: 'L2bpfSocket' object has no attribute 'ins'
Elias-MBP:~ Uni$ 

I read that it could be do to the program trying to close a L2bpfSocket that couldn't be created, therefore not having a Attribute ins.

However I have no clue how to fix this, or why the L2bpfSocket couldn't be created in the first place.

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35

1 Answers1

0

Make sure you're running your script as root.

The second issue isn't important, the main one being that Scapy can't open a /dev/bpf handler.

Cukic0d
  • 5,111
  • 2
  • 19
  • 48