2

我有一个wireshark .pcap 文件,我想从这个文件中获取所有资产(url、ip、电脑名称等)。我尝试使用我在网上找到的一些示例,但我在获取这些项目时遇到了一些问题。我设法找到了 dst 和 src 的 IP 地址,但仅此而已。

这是我当前的代码:

import pyshark

cap = pyshark.FileCapture('dor.pcap')

count = 0
for pkt in cap:
    ip_source = pkt.ip.__dict__["_all_fields"]["ip.src"]
    ip_address = pkt.ip.__dict__["_all_fields"]["ip.dst"]
4

1 回答 1

1

这应该与您的Wireshark pcap 文件一起使用,以获取源和目标地址和端口。可以修改输出(例如,csv、字典)以满足您的特定要求。

请提供有关您希望从 pcap 文件中解析的其他项目的更多详细信息。

import pyshark

def network_conversation(packet):
  try:
    protocol = packet.transport_layer
    source_address = packet.ip.src
    source_port = packet[packet.transport_layer].srcport
    destination_address = packet.ip.dst
    destination_port = packet[packet.transport_layer].dstport
    return (f'{protocol} {source_address}:{source_port} --> {destination_address}:{destination_port}')
  except AttributeError as e:
    pass

capture = pyshark.FileCapture('test.pcap')
conversations = []
for packet in capture:
  results = network_conversation(packet)
  if results != None:
    conversations.append(results)

# this sorts the conversations by protocol 
# TCP and UDP
for item in sorted(conversations):
  print (item)
于 2019-10-14T15:51:03.080 回答