scapython Debian中的错误

scapython Debian中的错误,debian,python,Debian,Python,下午好,我在Debian上创建了一个简单的嗅探器,但我无法运行它 from scapy.all import * counter = 0 def analysis(pkt): global counter print(counter, ": Ethernet") print("Src:", pkt["Ether"].src) print("Dst:", pkt["Ether&

下午好,我在Debian上创建了一个简单的嗅探器,但我无法运行它

from scapy.all import *


counter = 0

def analysis(pkt):
   global counter
   print(counter, ":  Ethernet")
   print("Src:", pkt["Ether"].src)
   print("Dst:", pkt["Ether"].dst)
   print(pkt.sprintf("Type: %Ether.type%"))

   if pkt["Ether"].type == 2054:     #ARP
      print("###ARP###")
      if pkt["ARP"].op == 1:
          print("echo-request")
      elif pkt["ARP"].op == 2:
          print("echo-reply")

   elif pkt["Ether"].type == 2048:   #IPv4
      print("###IPv4###")
      print("Src:", pkt["IP"].src)
      print("Dst:", pkt["IP"].dst)
      print("TTL:", pkt["IP"].ttl)
      print("High level protocol: ", pkt.sprintf("%IP.proto%"))    #udp 17
      print("Data size:", pkt["IP"].len-20)
      if pkt["IP"].proto == 17:
          print("     ###UDP###")
          print("     Src port:", pkt["UDP"].sport)
          print("     Dst port:", pkt["UDP"].dport)
          print("     Data size:", pkt["UDP"].len - 8)

  counter += 1
  print("---------------------------------------------------")


 if __name__ == '__main__':
    ifaces = os.listdir('/sys/class/net/')
    sniff(iface=ifaces, prn=analysis)
在Pycharm中运行时出错(在python3.7和3.9上尝试:

home/danya/Python-3.9.1/python /home/danya/PycharmProjects/main.py
  Traceback (most recent call last):
File "/home/danya/PycharmProjects/main.py", line 40, in <module>
  sniff(iface=ifaces, prn=analysis)
File "/home/danya/.local/lib/python3.9/site-packages/scapy/sendrecv.py", line 1263, in sniff
  sniffer._run(*args, **kwargs)
File "/home/danya/.local/lib/python3.9/site-packages/scapy/sendrecv.py", line 1127, in _run
  sniff_sockets[L2socket(type=ETH_P_ALL, iface=iface,
File "/home/danya/.local/lib/python3.9/site-packages/scapy/arch/linux.py", line 486, in init
  self.ins = socket.socket(
File "/home/danya/Python-3.9.1/Lib/socket.py", line 232, in init
  _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted

Process finished with exit code 1
home/danya/Python-3.9.1/Python/home/danya/PycharmProjects/main.py
回溯(最近一次呼叫最后一次):
文件“/home/danya/PycharmProjects/main.py”,第40行,在
嗅探(iface=iface,prn=分析)
文件“/home/danya/.local/lib/python3.9/site packages/scapy/sendrecv.py”,第1263行,在sniff中
嗅探器。_运行(*args,**kwargs)
文件“/home/danya/.local/lib/python3.9/site packages/scapy/sendrecv.py”,第1127行,在运行中
嗅探插座[L2插座(类型=ETH\U P\U ALL,iface=iface,
文件“/home/danya/.local/lib/python3.9/site packages/scapy/arch/linux.py”,第486行,在init中
self.ins=socket.socket(
文件“/home/danya/Python-3.9.1/Lib/socket.py”,第232行,在init中
_socket.socket.\uuuuu init\uuuuu(self、family、type、proto、fileno)
PermissionError:[Errno 1]不允许进行操作
进程已完成,退出代码为1

使用sudo权限运行


scaly需要sudo权限来嗅探接口上的流量

您能告诉我如何在Pycharm中执行此操作吗?您可以以root用户身份运行Pycharm。(此处存在安全问题)。或者您可以从命令行界面运行它(如果有)。很长时间没有使用pycharm,因此我不知道它是否有终端,但是。或者您可以编辑pycharm python配置文件以包含sudo。但这也将对不需要超级用户权限的脚本运行。最好的选择是在运行sudo py时从终端运行thon3*.py在终端中给出了相同的错误解决了一个问题:iface应该是字符串,而不是列表