权限错误:[Errno 1] 不允许操作

问题描述 投票:0回答:2

我对 python、linux RPI 和 scapy 完全陌生。我正在尝试使用 scapy 发送一些数据包。
在命令行上(仅当授予 scapy 超级用户权限时)

send(IP(dst="1.2.3.4")/ICMP())

在 python 脚本上运行时效果非常好。

from scapy.all import *
p=send(IP(dst="1.2.3.4")/ICMP())

抛出错误

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    send(IP(dst="1.2.3.4")/ICMP())
  File "/usr/local/lib/python3.4/dist-packages/scapy/sendrecv.py",line   255, in send
    __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
  File "/usr/local/lib/python3.4/dist-packages/scapy/arch/linux.py", line 326, in __init__
    self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
  File "/usr/lib/python3.4/socket.py", line 123, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted<br>

我正在尝试解决它,但无法解决,我对环境很陌生,因此了解不多。据我的搜索,这个问题与套接字有关。但我仍然需要一些简单的解释才能理解。

python-3.4 scapy
2个回答
13
投票

这意味着您需要使用 sudo/admin 权限启动脚本。


0
投票
when iam using sendp(frame,None) in scapy it showing this error.


                                                                                                                                                                                      
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
<ipython-input-15-1566ba531e46> in <module>
----> 1 sendp(frame,None)

~/.local/lib/python3.8/site-packages/scapy/sendrecv.py in sendp(x, iface, iface_hint, socket, **kargs)
    476     if iface is None and iface_hint is not None and socket is None:
    477         iface = conf.route.route(iface_hint)[0]
--> 478     return _send(
    479         x,
    480         lambda iface: iface.l2socket(),

~/.local/lib/python3.8/site-packages/scapy/sendrecv.py in _send(x, _func, inter, loop, iface, count, verbose, realtime, return_packets, socket, **kargs)
    412     need_closing = socket is None
    413     iface = resolve_iface(iface or conf.iface)
--> 414     socket = socket or _func(iface)(iface=iface, **kargs)
    415     results = __gen_send(socket, x, inter=inter, loop=loop,
    416                          count=count, verbose=verbose,

~/.local/lib/python3.8/site-packages/scapy/arch/linux.py in __init__(self, iface, type, promisc, filter, nofilter, monitor)
    482         self.type = type
    483         self.promisc = conf.sniff_promisc if promisc is None else promisc
--> 484         self.ins = socket.socket(
    485             socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
    486         self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)

/usr/lib/python3.8/socket.py in __init__(self, family, type, proto, fileno)
    229             if proto == -1:
    230                 proto = 0
--> 231         _socket.socket.__init__(self, family, type, proto, fileno)
    232         self._io_refs = 0
    233         self._closed = False

PermissionError: [Errno 1] Operation not permitted
© www.soinside.com 2019 - 2024. All rights reserved.