简体   繁体   English

隐藏Scapy警告消息IPv6

[英]Hide Scapy Warning Message IPv6

I tried multiple times to hide, but no success. 我多次尝试隐藏,但没有成功。 Any help? 有帮助吗?

I already tried - 我已经尝试过 -

from scapy.all import *
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)

Still get the same warning on console. 在控制台上仍然会收到相同的警告。

WARNING: No route found for IPv6 destination :: (no default route?)

FYI, I'm using Scapy with Python 2.7 on OS Mavericks. 仅供参考,我在OS Mavericks上使用Scapy和Python 2.7。

You need to import logging and adjust the settings for the logging message first. 您需要先导入日志记录并调整日志记录消息的设置。

What's happening is you import scapy into your namespace, trigger the error - and then change the logging settings. 发生的事情是将scapy导入命名空间,触发错误 - 然后更改日志记录设置。

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *

If you want to disable IPv6 in scapy but leave warnings (which is a good thing), use the following code: 如果要在scapy中禁用IPv6但保留警告(这是一件好事),请使用以下代码:

from scapy.config import conf
conf.ipv6_enabled = False
from scapy.all import *

The source code of scapy.all reveals this little secret. scapy.all源代码揭示了这个小秘密。

I know that this question is old, but I might have found an elegant answer. 我知道这个问题很老,但我可能找到了一个优雅的答案。 Are you building IPv6 packets? 你在构建IPv6数据包吗? If not, then what you could do is, instead of: 如果没有,那么你可以做的是,而不是:

from scapy.all import *

Use: 使用:

from scapy.layers.inet import IP

The problem is there are two IP classes, one in the package from scapy.layers.inet and one in from scapy.layers.inet6 . 问题是有两个IP类,一个来自scapy.layers.inet ,一个来自scapy.layers.inet6 Should you use the former import statement, you will import both even though you are only building version 4 packets. 如果您使用以前的import语句,即使您只构建版本4数据包,也将导入两者。

All of this is assuming you are intending to use IPv4 only, which I reckon is the case. 所有这一切都假设您打算仅使用IPv4,我认为是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM