scapy.contrib.bgp

BGP(边界网关协议).

class scapy.contrib.bgp.ASPathSegmentPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理AS_PATH段.

getfield(pkt, s)
class scapy.contrib.bgp.BGP

Bases: scapy.packet.Packet

每个BGP消息都从此类继承.

KEEPALIVE_TYPE = 4
NOTIFICATION_TYPE = 3
OPEN_TYPE = 1
ROUTEREFRESH_TYPE = 5
UPDATE_TYPE = 2
aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

返回给定数据的正确类.

guess_payload_class(p)
class scapy.contrib.bgp.BGPAuthenticationInformation

Bases: scapy.packet.Packet

提供Authentication Information可选参数的实现,该参数现在已过时. 参考:RFC 1771,RFC 1654,RFC 4271

aliastypes
fields_desc
BGPAuthenticationInformation字段

authentication_code

ByteField

0

authentication_data

StrField

None

class scapy.contrib.bgp.BGPCapFourBytesASN

Bases: scapy.contrib.bgp.BGPCapability

此类提供4字节AS号功能的实现. 参考:RFC 4893

aliastypes
fields_desc
BGPCapFourBytesASN字段

code

ByteEnumField

65

length

ByteField

4

asn

IntField

0

class scapy.contrib.bgp.BGPCapGeneric

Bases: scapy.contrib.bgp.BGPCapability

此类提供了通用功能的实现.

aliastypes
fields_desc
BGPCapGeneric字段

code

ByteEnumField

0

length

FieldLenField

None

cap_data

StrLenField

b''

class scapy.contrib.bgp.BGPCapGracefulRestart

Bases: scapy.contrib.bgp.BGPCapability

此类提供了Graceful Restart功能的实现. 参考:RFC 4724

class GRTuple

Bases: scapy.packet.Packet

元组<AFI,SAFI,地址族的标志>

aliastypes
fields_desc
GRTuple字段

afi

ShortEnumField

0

safi

ByteEnumField

0

flags

ByteEnumField

0

aliastypes
fields_desc
BGPCapGracefulRestart字段

code

ByteEnumField

64

length

ByteField

None

restart_flags

BitField (4位)

0

restart_time

BitField (12位)

0

entries

PacketListField

[]

class scapy.contrib.bgp.BGPCapMultiprotocol

Bases: scapy.contrib.bgp.BGPCapability

此类提供了Multiprotocol功能的实现. 参考:RFC 4760

aliastypes
fields_desc
BGPCapMultiprotocol字段

code

ByteEnumField

1

length

ByteField

4

afi

ShortEnumField

0

reserved

ByteField

0

safi

ByteEnumField

0

class scapy.contrib.bgp.BGPCapORF

Bases: scapy.contrib.bgp.BGPCapability

此类提供了出站路由筛选功能的实现. 参考:RFC 5291

aliastypes
fields_desc
BGPCapORF字段

code

ByteEnumField

3

length

ByteField

None

orf

BGPCapORFBlockPacketListField

[]

class scapy.contrib.bgp.BGPCapORFBlock

Bases: scapy.packet.Packet

" ORFBlock"由<AFI,rsvd,SAFI,ORF数量和<ORF类型,发送/接收>条目组成.

class ORFTuple

Bases: scapy.packet.Packet

数据包处理<ORF类型,发送/接收>元组.

aliastypes
fields_desc
ORFTuple栏位

orf_type

ByteEnumField

0

send_receive

ByteEnumField

0

aliastypes
fields_desc
BGPCapORFBlock字段

afi

ShortEnumField

0

reserved

ByteField

0

safi

ByteEnumField

0

orf_number

FieldLenField

None

entries

PacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPCapORFBlockPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

处理BGPCapORFB锁列表.

getfield(pkt, s)
class scapy.contrib.bgp.BGPCapability

Bases: scapy.packet.Packet

通用BGP能力.

aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

返回给定数据的正确类.

getlayer(cls, nb=1, _track=None, _subclass=True, **flt)
haslayer(cls)
post_build(p, pay)
pre_dissect(s)

检查有效载荷是否足够长(至少2个字节).

class scapy.contrib.bgp.BGPConf

Bases: scapy.config.ConfClass

BGP模块配置

use_2_bytes_asn = True
class scapy.contrib.bgp.BGPFieldIPv4(name, default, fmt='H')

Bases: scapy.fields.Field

IPv4字段(CIDR)

addfield(pkt, s, val)
getfield(pkt, s)
h2i(pkt, h)

xxxx / y为"内部"表示.

i2h(pkt, i)

从"内部"表示到"人类"表示(xxxx / y).

i2len(pkt, i)
i2m(pkt, i)

"内部"(IP为字节,掩码为int)表示"机器".

i2repr(pkt, i)
m2i(pkt, m)
mask2iplen(mask)

获取IP字段掩码长度(以字节为单位).

class scapy.contrib.bgp.BGPFieldIPv6(name, default, fmt='H')

Bases: scapy.fields.Field

IPv6字段(CIDR)

addfield(pkt, s, val)
getfield(pkt, s)
h2i(pkt, h)

xxxx / y为内部表示形式.

i2h(pkt, i)

从"内部"表示到"人类"表示.

i2len(pkt, i)
i2m(pkt, i)

"内部"(IP为字节,掩码为int)表示"机器".

i2repr(pkt, i)
m2i(pkt, m)
mask2iplen(mask)

获取IP字段掩码长度(以字节为单位).

class scapy.contrib.bgp.BGPHeader

Bases: scapy.packet.Packet

任何BGP消息的标头. 参考:RFC 4271

aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

返回给定数据的正确类.

fields_desc
BGPHeader字段

marker

XBitField (128位)

340282366920938463463374607431768211455

len

ShortField

None

type

ByteEnumField

4

guess_payload_class(payload)
payload_guess

可能的子层: BGPKeepAliveBGPNotificationBGPOpenBGPRouteRefreshBGPUpdate

post_build(p, pay)
class scapy.contrib.bgp.BGPKeepAlive

Bases: scapy.contrib.bgp.BGP, scapy.contrib.bgp.BGPHeader

KEEPALIVE消息.

aliastypes
class scapy.contrib.bgp.BGPNLRIPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理NLRI字段.

getfield(pkt, s)
class scapy.contrib.bgp.BGPNLRI_IPv4

Bases: scapy.packet.Packet

数据包处理IPv4 NLRI字段.

aliastypes
fields_desc
BGPNLRI_IPv4字段

prefix

BGPFieldIPv4

(0, '0.0.0.0')

class scapy.contrib.bgp.BGPNLRI_IPv6

Bases: scapy.packet.Packet

数据包处理IPv6 NLRI字段.

aliastypes
fields_desc
BGPNLRI_IPv6字段

prefix

BGPFieldIPv6

(0, '::')

class scapy.contrib.bgp.BGPNotification

Bases: scapy.contrib.bgp.BGP

通知消息结束BGP会话. 参考:RFC 4271

aliastypes
fields_desc
BGP通知字段

error_code

ByteEnumField

0

error_subcode

MultiEnumField (取决于error_code)

0

data

StrField

None

class scapy.contrib.bgp.BGPORF

Bases: scapy.packet.Packet

提供RR消息中携带的ORF的实现. 参考:RFC 5291

aliastypes
fields_desc
BGPORF字段

when_to_refresh

ByteEnumField

0

orf_type

ByteEnumField

0

orf_len

FieldLenField

None

entries

BGPORFEntryPacketListField

[]

class scapy.contrib.bgp.BGPORFAddressPrefix

Bases: scapy.contrib.bgp.BGPORFEntry

提供地址前缀ORF(RFC 5292)的实现.

aliastypes
fields_desc
BGPORFAddressPrefix字段

action

BitEnumField (2位)

0

match

BitEnumField (1位)

0

reserved

BitField (5位)

0

sequence

IntField

0

min_len

ByteField

0

max_len

ByteField

0

prefix

_ORFNLRIPacketField

b''

class scapy.contrib.bgp.BGPORFCoveringPrefix

Bases: scapy.packet.Packet

提供CP-ORF(RFC 7543)的实现.

aliastypes
fields_desc
BGPORFCoveringPrefix字段

action

BitEnumField (2位)

0

match

BitEnumField (1位)

0

reserved

BitField (5位)

0

sequence

IntField

0

min_len

ByteField

0

max_len

ByteField

0

rt

LongField

0

import_rt

LongField

0

route_type

ByteField

0

host_addr

PacketField

None

class scapy.contrib.bgp.BGPORFEntry

Bases: scapy.packet.Packet

提供一个ORF条目的实现. 参考:RFC 5291

aliastypes
fields_desc
BGPORFEntry字段

action

BitEnumField (2位)

0

match

BitEnumField (1位)

0

reserved

BitField (5位)

0

value

StrField

b''

class scapy.contrib.bgp.BGPORFEntryPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理ORF条目.

getfield(pkt, s)
m2i(pkt, m)
class scapy.contrib.bgp.BGPOpen

Bases: scapy.contrib.bgp.BGP

交换OPEN消息以打开新的BGP会话. 参考:RFC 4271

aliastypes
fields_desc
BGPOpen字段

version

ByteField

4

my_as

ShortField

0

hold_time

ShortField

0

bgp_id

IPField

'0.0.0.0'

opt_param_len

FieldLenField

None

opt_params

BGPOptParamPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPOptParam

Bases: scapy.packet.Packet

提供一个实现OPEN消息的可选参数. 参考:RFC 4271

aliastypes
fields_desc
BGPOptParam字段

param_type

ByteEnumField

2

param_length

ByteField

None

param_value

PacketField (Cond)

None

authentication_data

PacketField (Cond)

None

post_build(p, pay)
class scapy.contrib.bgp.BGPOptParamPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理可选参数(OPEN消息).

getfield(pkt, s)
class scapy.contrib.bgp.BGPPAAS4Aggregator

Bases: scapy.packet.Packet

提供AS4_AGGREGATOR属性"值部分"的实现. 参考:RFC 4893

aliastypes
fields_desc
BGPPAAS4Aggregator字段

aggregator_asn

IntField

0

speaker_address

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAAS4BytesPath

Bases: scapy.packet.Packet

包处理AS_PATH属性值(对于新扬声器,ASN为4字节-> ASN编码为IntFields). 参考:RFC 4893

class ASPathSegment

Bases: scapy.packet.Packet

提供具有4个字节ASN的AS_PATH段的实现.

aliastypes
fields_desc
ASPathSegment字段

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
aliastypes
fields_desc
BGPPAAS4BytesPath字段

segments

ASPathSegmentPacketListField

[]

class scapy.contrib.bgp.BGPPAAS4Path

Bases: scapy.packet.Packet

提供AS4_PATH属性"值部分"的实现. 参考:RFC 4893

aliastypes
fields_desc
BGPPAAS4Path字段

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPPAASPath

Bases: scapy.packet.Packet

数据包处理AS_PATH属性值(对于旧扬声器,为2字节ASN). 参考:RFC 4271,RFC 5065

class ASPathSegment

Bases: scapy.packet.Packet

提供具有2个字节ASN的AS_PATH段的实现.

aliastypes
fields_desc
ASPathSegment字段

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
AS_TRANS = 23456
aliastypes
fields_desc
BGPPAASPath字段

segments

ASPathSegmentPacketListField

[]

class scapy.contrib.bgp.BGPPAAggregator

Bases: scapy.packet.Packet

数据包处理AGGREGATOR属性值. 参考:RFC 4271

aliastypes
fields_desc
BGPPAAggregator字段

aggregator_asn

ShortField

0

speaker_address

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAAtomicAggregate

Bases: scapy.packet.Packet

数据包处理ATOMIC_AGGREGATE属性值. 参考:RFC 4271

aliastypes
class scapy.contrib.bgp.BGPPAClusterList

Bases: scapy.packet.Packet

数据包处理CLUSTER_LIST属性值. 参考:RFC 4456

aliastypes
fields_desc
BGPPAClusterList字段

cluster_list

FieldListField

[]

class scapy.contrib.bgp.BGPPACommunity

Bases: scapy.packet.Packet

数据包处理COMMUNITIES属性值. 参考:RFC 1997

aliastypes
fields_desc
BGPPACommunity字段

community

IntEnumField

0

class scapy.contrib.bgp.BGPPAExtCommFourOctetASSpecific

Bases: scapy.packet.Packet

数据包处理"四字节AS特定扩展社区"属性值. 参考:RFC 5668

aliastypes
fields_desc
BGPPAExtCommFourOctetASSpecific字段

global_administrator

IntField

0

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommIPv4AddressSpecific

Bases: scapy.packet.Packet

处理IPv4地址特定扩展社区属性值的数据包. 参考:RFC 4360

aliastypes
fields_desc
BGPPAExtCommIPv4AddressSpecific字段

global_administrator

IntField

0

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommOpaque

Bases: scapy.packet.Packet

处理不透明扩展社区属性值的数据包. 参考:RFC 4360

aliastypes
fields_desc
BGPPAExtCommOpaque字段

value

StrFixedLenField

b''

class scapy.contrib.bgp.BGPPAExtCommRedirectAS2Byte

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"重定向AS-2字节"扩展社区(RFC 7674). 参考:RFC 7674

aliastypes
fields_desc
BGPPAExtCommRedirectAS2Byte字段

asn

ShortField

0

value

IntField

0

class scapy.contrib.bgp.BGPPAExtCommRedirectAS4Byte

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"重定向AS-4byte"扩展社区. (RFC 7674). 参考:RFC 7674

aliastypes
fields_desc
BGPPAExtCommRedirectAS4Byte字段

asn

IntField

0

value

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommRedirectIPv4

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"重定向IPv4"扩展社区. (RFC 7674). 参考:RFC 7674

aliastypes
fields_desc
BGPPAExtCommRedirectIPv4字段

ip_addr

IntField

0

value

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommTrafficAction

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"流量动作"扩展社区. 参考:RFC 5575

aliastypes
fields_desc
BGPPAExtCommTrafficAction字段

reserved

BitField (46 bits)

0

sample

BitField (1位)

0

terminal_action

BitField (1位)

0

class scapy.contrib.bgp.BGPPAExtCommTrafficMarking

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"流量标记"扩展社区. 参考:RFC 5575

aliastypes
fields_desc
BGPPAExtCommTrafficMarking字段

dscp

BitEnumField (48位)

48

class scapy.contrib.bgp.BGPPAExtCommTrafficRate

Bases: scapy.packet.Packet

数据包处理(FlowSpec)"流量速率"扩展社区. 参考:RFC 5575

aliastypes
fields_desc
BGPPAExtCommTrafficRate fields

id

ShortField

0

rate

IEEEFloatField

0

class scapy.contrib.bgp.BGPPAExtCommTwoOctetASSpecific

Bases: scapy.packet.Packet

数据包处理" 2-Octet AS专用扩展社区"属性值. 参考:RFC 4360

aliastypes
fields_desc
BGPPAExtCommTwoOctetASSpecific字段

global_administrator

ShortField

0

local_administrator

IntField

0

class scapy.contrib.bgp.BGPPAExtComms

Bases: scapy.packet.Packet

分组处理多个扩展社区.

aliastypes
fields_desc
BGPPAExtComms字段

extended_communities

_ExtCommsPacketListField

[]

class scapy.contrib.bgp.BGPPAExtCommunity

Bases: scapy.packet.Packet

提供扩展社区属性的实现. 参考:RFC 4360

aliastypes
fields_desc
BGPPAExtCommunity字段

type_high

ByteEnumField

0

type_low

_TypeLowField

None

value

_ExtCommValuePacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPAIPv6AddressSpecificExtComm

Bases: scapy.packet.Packet

提供IPv6地址特定扩展社区属性的实现. 未使用现有的BGP扩展社区属性定义此属性(请参阅下面的RFC 5701摘录). 参考:RFC 5701

aliastypes
fields_desc
BGPPAIPv6AddressSpecificExtComm字段

global_administrator

IP6Field

'::'

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPALocalPref

Bases: scapy.packet.Packet

包处理LOCAL_PREF属性值. 参考:RFC 4271

aliastypes
fields_desc
BGPPALocalPref字段

local_pref

IntField

0

class scapy.contrib.bgp.BGPPAMPReachNLRI

Bases: scapy.packet.Packet

数据包处理非IPv6 AFI的MP_REACH_NLRI属性值. 参考:RFC 4760

aliastypes
fields_desc
BGPPAMPReachNLRI字段

afi

ShortEnumField

0

safi

ByteEnumField

0

nh_addr_len

ByteField

0

nh_v4_addr

IPField (Cond)

'0.0.0.0'

nh_v6_addr

IP6Field (Cond)

'::'

nh_v6_global

IP6Field (Cond)

'::'

nh_v6_link_local

IP6Field (Cond)

'::'

reserved

ByteField

0

nlri

MPReachNLRIPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPPAMPUnreachNLRI

Bases: scapy.packet.Packet

数据包处理非IPv6 AFI的MP_UNREACH_NLRI属性值. 参考:RFC 4760

aliastypes
fields_desc
BGPPAMPUnreachNLRI字段

afi

ShortEnumField

0

safi

ByteEnumField

0

afi_safi_specific

MPUnreachNLRIPacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPAMPUnreachNLRI_IPv6

Bases: scapy.packet.Packet

数据包,用于处理IPv6 AFI的MP_UNREACH_NLRI属性值.

aliastypes
fields_desc
BGPPAMPUnreachNLRI_IPv6字段

withdrawn_routes

BGPNLRIPacketListField

[]

class scapy.contrib.bgp.BGPPAMultiExitDisc

Bases: scapy.packet.Packet

数据包处理MULTI_EXIT_DISC属性值. 参考:RFC 4271

aliastypes
fields_desc
BGPPAMultiExitDisc字段

med

IntField

0

class scapy.contrib.bgp.BGPPANextHop

Bases: scapy.packet.Packet

数据包处理NEXT_HOP属性值. 参考:RFC 4271

aliastypes
fields_desc
BGPPANextHop字段

next_hop

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAOrigin

Bases: scapy.packet.Packet

包处理ORIGIN属性值. 参考:RFC 4271

aliastypes
fields_desc
BGPPAO原始字段

origin

ByteEnumField

0

class scapy.contrib.bgp.BGPPAOriginatorID

Bases: scapy.packet.Packet

包处理ORIGINATOR_ID属性值. 参考:RFC 4456

aliastypes
fields_desc
BGPPAOriginatorID字段

originator_id

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPathAttr

Bases: scapy.packet.Packet

提供路径属性的实现. 参考:RFC 4271

aliastypes
fields_desc
BGPPathAttr字段

type_flags

FlagsField (8位)

<Flag 128 (Optional)>

type_code

ByteEnumField

0

attr_ext_len

ShortField (Cond)

None

attr_len

ByteField (Cond)

None

attribute

_PathAttrPacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPathAttrPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理路径属性(UPDATE消息).

getfield(pkt, s)
class scapy.contrib.bgp.BGPRouteRefresh

Bases: scapy.contrib.bgp.BGP

提供ROUTE-REFRESH消息的实现. 参考:RFC 2918,RFC 7313

aliastypes
fields_desc
BGPRouteRefresh字段

afi

ShortEnumField

1

subtype

ByteEnumField

0

safi

ByteEnumField

1

orf_data

PacketField

b''

class scapy.contrib.bgp.BGPUpdate

Bases: scapy.contrib.bgp.BGP

UPDATE消息允许对等方交换路由. 参考:RFC 4271

aliastypes
fields_desc
BGPUpdate字段

withdrawn_routes_len

FieldLenField

None

withdrawn_routes

BGPNLRIPacketListField

[]

path_attr_len

FieldLenField

None

path_attr

BGPPathAttrPacketListField

[]

nlri

BGPNLRIPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.MPReachNLRIPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField处理MP_REACH_NLRI属性的AFI特定部分("下一跳网络地址"字段的长度,但不是AFI特定).

getfield(pkt, s)
class scapy.contrib.bgp.MPUnreachNLRIPacketField(name, default, cls, remain=0)

Bases: scapy.fields.PacketField

PacketField处理MP_UNREACH_NLRI属性的AFI特定部分.

m2i(pkt, m)
scapy.contrib.bgp.has_extended_length(flags)

在BGPPathAttr中使用,以检查是否设置了扩展长度标志.