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

拟墨画扇 提交于 2019-12-10 14:45:57

问题


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

WARNING: can't import layer ipsec: 'module' object has no attribute '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 !

I tried edit lines in ipsec.py such as:

    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 ?


回答1:


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

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.10 on a variety of OSes (Lnx, Sol, AIX, HPUX, OSX) and the values seem to be consistent, while on Win they don't exist. Seems like MS removed them from WinSock2.h between (VStudio) 2005 and 2010.



来源:https://stackoverflow.com/questions/30579611/ipsec-py-cant-find-the-attribute-ipproto-esp-and-socket-ipproto-ah

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!