PROBLEM WHILE USING SCAPY (Permission denied)

Question:

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
Asked By: Faiyaz Ahmad

||

Answers:

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

Answered By: m0hithreddy

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".

Answered By: Giorgos Xou

use sudo like this sudo -E python3 Arpt.py

Answered By: Nune ashokkumar

how to use sudo in the above code in Mac OS?(in Anaconda)?

Answered By: pawan krishna