【发布时间】:2021-07-10 05:21:32
【问题描述】:
试图围绕我为 Scapy 找到的一段代码展开思考。
from scapy.utils import RawPcapReader
from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, TCP
for pkt_data, pkt_metadata in RawPcapReader(file_name):
ether_pkt = Ether(pkt_data)
if 'type' not in ether_pkt.fields:
# LLC frames will have 'len' instead of 'type'.
# We disregard those
continue
if ether_pkt.type != 0x0800:
# disregard non-IPv4 packets
continue
ip_pkt = ether_pkt[IP]
让我困惑的部分是我的对象 ether_pkt 被分配到类 Ether 但是随着 ip_pkt = ether_pkt[IP]
的变化这里发生了什么?
【问题讨论】: