Scapy BGP标志属性

时间:2016-08-25 15:39:23

标签: python networking scapy bgp

有没有其他方法可以使用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

1 个答案:

答案 0 :(得分:1)

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

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.