2016-08-25 5 views
0

Gibt es eine andere Möglichkeit, Scapy zu verwenden, um ein Paket mit mehreren Flag-Attributen zu konfigurieren?Scapy BGP Flags Attribut

Ich versuche, eine BGP-Schicht mit optionalen und transitiven Attributen einzurichten. Ich verwende diese Github-Datei: https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py. In Zeile 107 sind die Flags, die ich hinzufügen möchte.

Vergangenheit gescheiterten Versuche umfassen:

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

Antwort

1

Es ist möglich, mehrere Flag Attribute zu konfigurieren, indem sie in einem einzelnen String aufzählt, begrenzt mit dem '+' Zeichen:

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. 

Eine alternative Methode, um den numerischen Wert der gewünschten Kombination von Flags direkt zu berechnen, ist der Vollständigkeit halber vorgesehen:

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

Danke, ich fand einen anderen Weg, falls Sie neugierig sind, flags = 192 setzt es auf Optional und Transitiv. –

+0

Ich habe es versäumt, es zu erwähnen, da ich es nicht als elegant empfinde, aber ich habe es jetzt der Vollständigkeit halber aufgenommen; Vielen Dank! – Yoel