Python ipsec.py 找不到属性 IPPROTO_ESP 和 socket.IPPROTO_AH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30579611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:39:39  来源:igfitidea点击:

ipsec.py CANT FIND THE attribute IPPROTO_ESP and socket.IPPROTO_AH

pythonsocketsscapyipsec

提问by yosi doran

I install the module scapy for python 2.6 and when I import this module I get this warning:

我为 python 2.6 安装了模块 scapy,当我导入这个模块时,我收到了这个警告:

WARNING: can't import layer ipsec: 'module' object has no attribute 'IPPROTO_AH'

警告:无法导入层 ipsec:“模块”对象没有属性“IPPROTO_AH”

I looked in the socket attributes and i didnt find the 'IPPROTO_AH' attribute In addition, i tried to edit the module ipsec.py and find way to replace IPPROTO_AH with something else but then i got WARNING WITH IPPROTO_ESP !

我查看了套接字属性,但没有找到“IPPROTO_AH”属性此外,我尝试编辑模块 ipsec.py 并找到用其他东西替换 IPPROTO_AH 的方法,但后来我收到了 IPPROTO_ESP 警告!

I tried edit lines in ipsec.py such as:

我尝试在 ipsec.py 中编辑行,例如:

    overload_fields = {
    IP: {'proto': IPTest},
    IPv6: {'nh': IPTest},
    IPv6ExtHdrHopByHop: {'nh': socket.IPPROTO_AH},
    IPv6ExtHdrDestOpt: {'nh': socket.IPPROTO_AH},
    IPv6ExtHdrRouting: {'nh': socket.IPPROTO_AH},}

bind_layers(IP, AH, proto=socket.IPPROTO_AH)
bind_layers(IPv6, AH, nh=socket.IPPROTO_AH)

how can i fix this ?

我怎样才能解决这个问题 ?

采纳答案by CristiFati

I think I have it...it's not a clean solution, but it will do the trick... I've seen it in other scapyfiles...
All you need to do is edit ipsec.pyand look for the line import socketjust under it, add these conditionals:

我想我有它......这不是一个干净的解决方案,但它可以解决问题......我在其他scapy文件中看到过......
你需要做的就是编辑ipsec.py并查找该行import socket就在它下面,添加这些条件:

if not hasattr(socket, "IPPROTO_ESP"):
    socket.IPPROTO_ESP = 50
if not hasattr(socket, "IPPROTO_AH"):
    socket.IPPROTO_AH = 51

As I mentioned in one of the comments, I tested using Python 2.7.10on a variety of OSes (Lnx, Sol, AIX, HPUX, OSX) and the values seem to be consistent, while on Winthey don't exist. Seems like MSremoved them from WinSock2.hbetween (VStudio) 2005and 2010.

正如我在其中一条评论中提到的,我在各种操作系统LnxSolAIXHPUXOSX)上使用Python 2.7.10进行了测试,这些值似乎是一致的,而在Win 上它们不存在。似乎MS在 ( VStudio) 20052010之间从WinSock2.h 中删除了它们。