使用 pyshark 从 SMTP 数据包中获取 "To" 和 "From" 字段

Getting the "To" and "From" fields from a SMTP packet using pyshark

如何从与流隔离的 SMTP 数据包中获取 "To" 和 "From" 类别。

import pyshark

fileBuffer = pyshark.FileCapture(pcapDirectory)
samplePacket = fileBuffer[SMTP_Packet_Location]

# Get to and from fields

我找到了以下解决方案:

fileBuffer = pyshark.FileCapture(pcapDirectory)
samplePacket = fileBuffer[SMTP_Packet_Location]
print(samplePacket.smtp.get_field_value("req_parameter"))

输出:

TO: <exampleEmail@provider.com>