V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
weiyu
V2EX  ›  Python

scapy 构造 IP 报文时 options 字段填充出错

  •  
  •   weiyu · 2015-07-30 17:59:05 +08:00 · 2189 次点击
    这是一个创建于 3436 天前的主题,其中的信息可能已经有所发展或是发生改变。

    具体参见下面的idle

    from scapy.all import *
    WARNING: No route found for IPv6 destination :: (no default route?)
    packet = IP(options='0x11')
    packet.display()

    [ IP ]

    version = 4
    ihl = None
    tos = 0x0
    len = None
    id = 1
    flags =
    frag = 0
    ttl = 64
    proto = ip
    chksum = None
    src = 127.0.0.1
    dst = 127.0.0.1
    \options \
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/site-packages/scapy/packet.py", line 794, in display
    self.show(args,*kargs)
    File "/usr/lib/python2.7/site-packages/scapy/packet.py", line 816, in show
    fvalue.show(indent=indent, labellvl=label_lvl+lvl+" |")
    AttributeError: 'str' object has no attribute 'show'
    send(packet)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/site-packages/scapy/sendrecv.py", line 251, in send
    __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
    File "/usr/lib/python2.7/site-packages/scapy/sendrecv.py", line 234, in __gen_send
    s.send(p)
    File "/usr/lib/python2.7/site-packages/scapy/arch/linux.py", line 387, in send
    sx = str(ll(x))
    File "/usr/lib/python2.7/site-packages/scapy/arch/linux.py", line 385, in <lambda>
    ll = lambda x:conf.l2typessn[3]/x
    File "/usr/lib/python2.7/site-packages/scapy/packet.py", line 267, in __div
    _
    cloneB = other.copy()
    File "/usr/lib/python2.7/site-packages/scapy/packet.py", line 147, in copy
    clone.fields[k]=self.get_field(k).do_copy(clone.fields[k])
    File "/usr/lib/python2.7/site-packages/scapy/fields.py", line 413, in do_copy
    return map(lambda p:p.copy(), x)
    File "/usr/lib/python2.7/site-packages/scapy/fields.py", line 413, in <lambda>
    return map(lambda p:p.copy(), x)
    AttributeError: 'str' object has no attribute 'copy'

    3 条回复    2017-03-21 14:50:54 +08:00
    weiyu
        1
    weiyu  
    OP
       2015-07-31 09:07:25 +08:00
    看来没有多少做网络的同学,此帖要沉~
    还有,格式完全不对啊,新手表示略无力= =
    weiyu
        2
    weiyu  
    OP
       2015-07-31 10:00:24 +08:00
    问题解决了,感谢强大的google= =
    options字段需要调用IPOption()方法进行封装,如下即可:
    packet.options = IPOption('\x83\x03\x10')
    paladin437
        3
    paladin437  
       2017-03-21 14:50:54 +08:00
    我想构造的是 loose_source_route 。这个地址怎么插入啊,这个貌似都搜索不到。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5986 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 02:08 · PVG 10:08 · LAX 18:08 · JFK 21:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.