1

I am trying to make a simple network scanner in python3 which can scan whole devices on LAN. That's when i heard about Scapy. However, whenever i try to run my program, it returns an error "PermissionError: [Errno 13] Permission denied"

Here's my code:

import scapy.all as scapy


def scan(ip):

  scapy.arping(ip)

scan("192.168.43.1")

It would help me a lot if you guys can fix this issue. Thanks for reading.

COMPLETE OUTPUT:

          Traceback (most recent call last):
         File "network_scanner.py", line 7, in <module>
         scan("192.168.43.1")
         File "network_scanner.py", line 5, in scan
         scapy.arping(ip)
         File "/usr/local/lib/python3.8/dist- 
         packages/scapy/layers/l2.py", line 628, in arping
         ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / 
         ARP(pdst=net), verbose=verbose,  # noqa: E501
         File "/usr/local/lib/python3.8/dist- 
         packages/scapy/sendrecv.py", line 503, in srp
         s = conf.L2socket(promisc=promisc, iface=iface,
         File "/usr/local/lib/python3.8/dist- 
        packages/scapy/arch/linux.py", line 467, in __init__
        self.ins = socket.socket(socket.AF_PACKET, 
        socket.SOCK_RAW, socket.htons(type))  # noqa: E501
       File "/usr/lib/python3.8/socket.py", line 231, in __init__
       _socket.socket.__init__(self, family, type, proto, fileno)
       PermissionError: [Errno 13] Permission denied
Faiyaz Ahmad
  • 87
  • 1
  • 6

2 Answers2

2

I Had the same Issue but with "[Errno 1]" , what solved it for me was to just use root permissions via sudo (and "-E" to preserve the enviroment) like:

sudo -E python myScriptName.py

As mentioned Here too. | ⚠️ "It comes with it's own security risks. So be careful".

Giorgos Xou
  • 1,461
  • 1
  • 13
  • 32
1

I beleive the method scapy.arping() opens raw socket. Try running as root user with sudo.

m0hithreddy
  • 1,752
  • 1
  • 10
  • 17