0

複数のフラグ属性を持つパケットを構成するために Scapy を使用できる他の方法はありますか?

オプションの属性と推移的な属性の両方を使用して 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
4

1 に答える 1

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.
于 2016-08-25T16:58:10.300 に答える