读取pyshark IEEE802.1AD层剖析器值时出现问题

2024-09-30 05:21:32 发布

您现在位置:Python中文网/ 问答频道 /正文

背景:
我试图使用pyshark模块来剖析包含triple 802.1AD tags的包。当打印包的层时,存在两个IEEE8021AD层。在

 [<ETH Layer>, <IEEE8021AD Layer>, <IEEE8021AD Layer>, <IP Layer>, <DATA Layer>]

从同一个包的Wireshark显示可以看出,第一个IEEE8021AD层包含两个VLAN标签,第二层包含第三个标签:

Wireshark packet dissection

问题:

  1. I can't figure out how to access the 2nd IEEE802.1AD layer using the pyshark module since both layers have the same name.

  2. In the 1st IEEE802.1AD layer, I can access the DEI and Priority fields of the 1st VLAN, but not the same values for the 2nd VLAN. The dissector field names for DEI and Priority are the same between the two VLANS that share this layer.

Wireshark为这个包导出的XML显示了两个具有相同名称的ieee8021ad层,以及具有相同名称的dei和priority dissector字段:

^{pr2}$

我尝试使用pprint模块来查看数据结构,但是在尝试打印层时没有有用的输出。在

#!/usr/bin/python

from __future__ import print_function
import pyshark
import pprint

cap = pyshark.FileCapture(filename)

pp = pprint.PrettyPrinter(indent=4)

for i, pkt in enumerate(cap):

    print("----------------- Packet %d --------------------" % i)
    print(pkt.layers)

    print(pkt.ieee8021ad)

    print("        dei      = %s" % pkt.ieee8021ad.dei)
    print("        priority = %s" % pkt.ieee8021ad.priority)
    print("        cvid     = %s" % pkt.ieee8021ad.cvid)
    print("        svid     = %s" % pkt.ieee8021ad.svid)
    #print("        type     = %s" % pkt.ieee8021ad.type)  # 'type'     doesn't exist>

代码输出:

----------------- Packet 1 --------------------
[<ETH Layer>, <IEEE8021AD Layer>, <IEEE8021AD Layer>, <IP Layer>, <DATA Layer>]
Layer IEEE8021AD:
    101. .... .... .... = Priority: 5
    ...1 .... .... .... = DEI: 1
    .... 0000 0000 1000 = ID: 8
    Type: 802.1ad Provider Bridge (Q-in-Q) (0x88a8)
    .... 0000 0000 1001 = ID: 9
    100. .... .... .... = Priority: 4
    ...0 .... .... .... = DEI: 0

    dei      = 1   # Drop Eligibility Indicator for VLAN #2
    priority = 5   # Priority for VLAN #2
    cvid     = 8   # ID for VLAN #2
    svid     = 9   # ID for VLAN #1

Tags: thelayeridforadprintprioritypyshark

热门问题