Scapy BGP 标志属性

Scapy BGP Flags Attribute

有没有其他方法可以使用 Scapy 配置具有多个标志属性的数据包?

我正在尝试设置具有可选属性和传递属性的 BGP 层。我正在使用这个 github 文件:https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py。第 107 行是我要添加的标志。

过去失败的尝试包括:

>>>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

可以通过在单个字符串中枚举它们来配置多个标志属性,用 '+' 符号分隔:

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.

为了完整起见,提供了另一种方法,直接计算所需标志组合的数值:

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.