2016-08-25 55 views
0

是否有任何其他方式可以使用Scapy配置具有多个标志属性的数据包?Scapy BGP标志属性

我正在尝试设置一个带有可选属性和传递属性的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

有可能通过在单一的字符串列举它们配置多个标志的属性,与所述'+'符号分隔:

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. 
+0

谢谢,我发现另一种方式,以防万一你好奇,flags = 192将它设置为Optional和Transitive。 –

+0

我忽略提及它,因为我没有觉得它是优雅的,但我已经为了完整而将它包括在内;谢谢! – Yoel