2016-08-25 6 views
0

Scapyを使用して複数のフラグ属性を持つパケットを設定する方法はありますか?Scapy BGP Flags属性

私は、オプションの推移の両方の属性を持つ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

おかげで、私はフラグ= 192セット、それはオプションと推移の両方に、あなたが興味がある場合には別の方法を発見しました。 –

+0

私はそれをエレガントなものとは見なしていないので、私はそれに言及しませんでしたが、今は完璧のためにそれを含めました。ありがとう! – Yoel