以下是使用 Python 的 scapy
库从读取的 PCAP 文件数据包中获取源 IP 的示例代码:
python
from scapy.all import *
def get_source_ip(pcap_file):
packets = rdpcap(pcap_file)
for packet in packets:
if packet.haslayer(IP):
source_ip = packet[IP].src
print("Source IP: ", source_ip)
# 请将 'your_pcap_file.pcap' 替换为实际的 PCAP 文件路径
get_source_ip('your_pcap_file.pcap')