2016-08-25 81 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