I am using scapy to send a packet. which works fine in command line under the code.
But when I try to send it inside shell it throws an error. The code I am using is
from scapy.all import * packet=send(IP(dst="www.google.com")/ICMP())
It throws an error
Traceback (most recent call last): File "/home/pi/111.py", line 2, in <module> packet=send(IP(dst="www.google.com")/ICMP()) File "/usr/local/lib/python2.7/dist-packages/scapy/sendrecv.py", line 268, in send return __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, File "/usr/local/lib/python2.7/dist-packages/scapy/arch/linux.py", line 324, in __init__ self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) File "/usr/lib/python2.7/socket.py", line 187, in __init__ _sock = _realsocket(family, type, proto) error: [Errno 1] Operation not permitted
But when I use
sudo python 'file_name.py' in command line it works fine. Previously this command was not working as well untill I set RAW Scokets in shell using
sudo setcap -v cap_net)raw+eip/usr/bin/python2.7
In my opinion this issue is related to RAW sockets which scapy uses to send the packet and it needs sudo privileges. But I don't know how to fix it for shell or script which I can run in shell not in command line. Your feedback in easy explanation is expected as I am newbie to all this.