未解决的参考与船头 [英] Unresolved reference with scapy

查看:91
本文介绍了未解决的参考与船头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用用scapy用python编写的网络工具.
作为IDE,我正在使用Pycharm.
我的代码有效.因此,如果我运行它,一切都会按预期进行.

I am working on a network tool that I write in python using scapy.
As IDE I am using Pycharm.
My Code works. So if I run it, everything works just as intended.

我的问题是PyCharm给了我一些错误.
它将IPTCPEther,...的每次使用标记为Undefined Reference to ...

My problem is that PyCharm is giving me some errors.
It marks every use of IP, TCP, Ether, ... as Undefined Reference to ...

我的代码的相关部分如下所示

The relevant parts of my Code look like this

#!/usr/bin/env python
from scapy.all import *

...  
...  

syn = IP(src=src_ip, dst=dst_ip) / TCP(sport=src_port, dport=dst_port, seq=src_seq, flags="S")

...

我尝试了很多使用google发现的事情,例如将src文件夹添加为源根目录,刷新了所有可以找到的缓存,并重启了PyCharm数十次,但无济于事...

I tried many things I found using google, like adding my src folder as source root, I refreshed all caches I could find and restarted PyCharm dozens of times, but nothing worked...

由于代码正常工作,这是一个小问题,但我仍然希望我的IDE能够按预期工作

Since the code works it's a minor problem, but still I'd like to have my IDE working as intended

我在MacOS上工作,并且使用了虚拟环境

I am working under MacOS and I use a Virtual Environment

推荐答案

这是一个PyCharm问题. Scapy使用动态加载(使用importlib)加载许多pycharm无法检测到的模块/自定义模块.这样,用户可以选择要加载的图层.

This is a PyCharm issue. Scapy uses dynamic loading (using importlib) to load many modules / custom modules, that pycharm does not detect. This allows the users to select which layers they want to have loaded.

解决方法是从相关的scapy文件中导入所需的任何内容,而无需使用all.它比较干净,但是需要做的时间更长.或者,如果您不想要干净的东西,也可以在IDE中使用添加例外".

The workaround is to import whatever you need from their related scapy file, without using all. It is cleaner but longer to do. Or you can use "add an exception" in your IDE, if you’re not looking for something clean.

以下是一些有用的模块

  • scapy.layers.inet,您可以在其中获取IP,TCP.
  • scapy.layers.inet6
  • scapy.layers.dns
  • scapy.sendrecv具有srp,sr,sr1,sendp,send ...
  • scapy.supersocket直接访问scapy的套接字
  • scapy.layers.l2具有ARP以太网..
  • scapy.layers.dot11用于802.11内容
  • scapy.utils表示wrpcaprdpcap ...
  • scapy.config用于conf对象(具有conf.routeconf.route6之类的属性)
  • scapy.layers.inet where you can get IP, TCP..
  • scapy.layers.inet6
  • scapy.layers.dns
  • scapy.sendrecv has srp, sr, sr1, sendp, send...
  • scapy.supersocket to directly access scapy’s sockets
  • scapy.layers.l2 which has Ether, ARP..
  • scapy.layers.dot11 for 802.11 stuff
  • scapy.utils for wrpcap, rdpcap...
  • scapy.config for the conf object (which has properties such as conf.route or conf.route6)

我建议做的是打开Scapy shell(或在控制台中导入from scapy.all import *),并使用help(...)

What I advise to do is to open the Scapy shell (or import from scapy.all import * in a console) and check from which module a layer/function is by using help(...)

这篇关于未解决的参考与船头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆