【问题标题】:How to open a pcap file with Wireshark scapy?如何使用 Wireshark scapy 打开 pcap 文件?
【发布时间】:2020-05-18 23:49:35
【问题描述】:

我编写了一个 python V3 脚本,它可以嗅探 10 个包,编写日志并在 Wireshark 中打开日志。但不知何故,它总是在 /tmp 中打开一个空日志

我的代码:

#!/usr/bin/env python3
import sys
from scapy.all import *
x = sniff(count=10)
wrpcap('log', x, append=False)

wireshark('log')

输出:

WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
WARNING: PcapWriter: unknown LL type for str. Using type 1 (Ethernet)
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
ERROR: 'str' object has no attribute 'sent_time'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

它应该打开日志而不是变量,但我不知道如何。

scapy 文档 (https://readthedocs.org/projects/scapy/downloads/pdf/latest/) 说:

使用文件名(作为字符串传递),这会在 Wireshark 中加载给定文件。这需要在一个 Wireshark 支持的格式。

有人知道如何在 Wireshark 中打开 pcap 日志吗?

【问题讨论】:

  • 嗯,看起来确实很奇怪。您使用的是哪个版本的 scapy?确保它是最新的。
  • 我会将名称更改为log.pcap,以便它具有扩展名。
  • @RossJacobs 将名称更改为 log.pcap 会得到相同的结果。 Scapy 自动将日志写入为 .pcap 文件。
  • @Cukic0d 我正在使用最新版本的 python3-scapy (0.23-1)

标签: python-3.x wireshark scapy


【解决方案1】:

我通过CTRL+点击wireshark('log')找到了wireshark()方法。

def wireshark(pktlist, *args):
    """Run wireshark on a list of packets"""
    fname = get_temp_file()
    wrpcap(fname, pktlist)
    subprocess.Popen([conf.prog.wireshark, "-r", fname] + list(args))

它似乎总是创建一个临时文件,因为该方法希望接收一个变量列表,然后打开临时文件。

我可以直接在我的代码中使用subprocess.Popen([conf.prog.wireshark, "-r", fname] + list(args) 来修复它,而不是使用'wireshark('log')'。

工作代码:

#!/usr/bin/env python3
import sys
from scapy.all import *

x = sniff(count=10)
wrpcap('log', x, append=False)

subprocess.Popen([conf.prog.wireshark, "-r", 'log'])

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 2018-03-10
    • 2020-04-20
    • 1970-01-01
    • 2021-06-01
    • 2016-02-17
    相关资源
    最近更新 更多