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