[英]Scapy BGP Flags Attribute
Is there any other way I could use Scapy to configure a packet with multiple flag attributes? 我还有其他方法可以使用Scapy配置具有多个标志属性的数据包吗?
I am trying to set up a BGP Layer with both optional and transitive attributes. 我正在尝试使用可选属性和可传递属性设置BGP层。 I am using this github file: https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py .
我正在使用这个github文件: https : //github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py 。 On line 107, is the flags I am trying to add.
在第107行,是我要添加的标志。
Past failed attempts include: 过去失败的尝试包括:
>>>a=BGPPathAttribute(flags=["Optional","Transitive"])
>>>send(a)
TypeError: unsupported operand type(s) for &: 'str' and 'int'
>>>a=BGPPathAttribute(flags=("Optional","Transitive"))
>>>send(a)
TypeError: unsupported operand type(s) for &: 'tuple' and 'int'
>>>a=BGPPathAttribute(flags="Optional")/BGPPathAttribute(flags="Transitive")
Creates 2 separate path attributes: One which is Optional and Non-Transitive and the other which is Well Known and Transitive.
>>>a=BGPPathAttribute(flags="Optional", flags="Transitive")
SyntaxError: keyword argument repeated
>>>a=BGPPathAttribute(flags="OT")
ValueError: ['OT'] is not in list
It is possible to configure multiple flag attributes by enumerating them in a single string, delimited with the '+'
sign: 可以通过在一个字符串中枚举多个标记属性来配置多个标记属性,这些字符串以
'+'
分隔:
In [1]: from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)
In [2]: from scapy.contrib.bgp import BGPPathAttribute
In [3]: BGPPathAttribute(flags='Optional+Transitive')
Out[3]: <BGPPathAttribute flags=Transitive+Optional |>
In [4]: send(_)
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent 1 packets.
An alternative method, to directly calculate the numerical value of the desired combination of flags, is provided for completeness' sake: 为完整性起见,提供了一种替代方法,直接计算所需标志组合的数值:
In [1]: from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)
In [2]: from scapy.contrib.bgp import BGPPathAttribute
In [3]: BGPPathAttribute(flags='Optional').flags | BGPPathAttribute(flags='Transitive').flags
Out[3]: 192
In [4]: BGPPathAttribute(flags=_)
Out[4]: <BGPPathAttribute flags=Transitive+Optional |>
In [5]: send(_)
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent 1 packets.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.