PyCharm:Scapy 未解决的引用 [英] PyCharm: Unresolved reference with Scapy

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

问题描述

我正在开发一个使用 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 给了我一些错误.
它将 IP, TCP, Ether, ... 的每次使用标记为 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 有 Ether, 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 检查层/函数来自哪个模块(...).您还可以通过 这里查看在线 API 参考(它有一个搜索栏)

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(...). You can also check out the online API reference (it has a search bar) over here

这篇关于PyCharm:Scapy 未解决的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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