0

I am using scapy to send a packet. which works fine in command line under the code.

send(IP(dst="www.google.com")/ICMP())

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.

asked Jun 2, 2017 at 8:30

1 Answer 1

0
answered Jun 2, 2017 at 9:55
3
  • 1
    It would be nice to see a summary of the information contained in the link featured in your answer... Commented Jun 2, 2017 at 11:14
  • That link was the first google result for '_sock = _realsocket(family, type, proto)'. But it's on stack overflow, so I didn't want to flag this as a duplicate. Commented Jun 2, 2017 at 13:40
  • I can run the script using 'sudo' in command line interface but unable to run it within the python shell. so basically I don't know how to give admin rights to python script while running it inside python shell. Of course I can use "sudo fileName.py" in CLI but can't do it inside shell. Commented Jun 20, 2017 at 12:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.