是否有用于 Wireshark 的 API 来开发与其交互/增强它的程序/插件? [英] Is there an API for Wireshark, to develop programs/plugins that interact with it/enhance it?

查看:21
本文介绍了是否有用于 Wireshark 的 API 来开发与其交互/增强它的程序/插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌搜索没有给我很好的结果.是否有任何类型的 Wireshark API 可以从主要源代码中抽象出来,以便我们可以开发与其交互并处理它提供的数据的程序?

我很欣赏有关接收数据包的不同方式的建议,但我想将数据包注入到 Wireshark 中.嗅探将是我项目的重要组成部分,但是我不确定建议的解决方案是否允许数据包注入.

解决方案

我使用 pypcap 读取数据包和 dpkt 到解析.

例如,使用 dpkt 从保存的 pcap 中读取数据包:

导入套接字导入dpkt导入系统pcapReader = dpkt.pcap.Reader(file(sys.argv[1], "rb"))对于 ts,pcapReader 中的数据:以太 = dpkt.ethernet.Ethernet(数据)如果 ether.type != dpkt.ethernet.ETH_TYPE_IP: 提高ip = ether.datasrc = socket.inet_ntoa(ip.src)dst = socket.inet_ntoa(ip.dst)打印 "%s -> %s" % (src, dst)

使用 pypcap 从网络上抓取帧:

 导入 pcappc = pcap.pcapObject()dev = sys.argv[1]pc.open_live(dev, 1600, 0, 100)pc.setfilter("udp 端口​​ 53", 0, 0)而 1:pc.dispatch(1, p.pcap_dispatch)

当然,两者可以一起使用:(摘自pypcap的主页)

<预><代码>>>>导入 dpkt、pcap>>>pc = pcap.pcap()>>>pc.setfilter('icmp')>>>对于 ts,pct 中的 pkt:...打印`dpkt.ethernet.Ethernet(pkt)`

祝你好运!

Googling didn't give me great results. Is there any sort of API for Wireshark that abstracts away from the main source code so we can develop programs that interact with it and deal with the data it provides?

edit: I appreciate the suggestions for different ways to receive packets, but I want to implement packet injection into Wireshark. Sniffing will be an important part of my project, however I'm not sure that the suggested solution allows for packet injection.

解决方案

I use pypcap to read packets and dpkt to parse.

For example, to use dpkt to read packets from a saved pcap:

import socket
import dpkt
import sys
pcapReader = dpkt.pcap.Reader(file(sys.argv[1], "rb"))
for ts, data in pcapReader:
    ether = dpkt.ethernet.Ethernet(data)
    if ether.type != dpkt.ethernet.ETH_TYPE_IP: raise
    ip = ether.data
    src = socket.inet_ntoa(ip.src)
    dst = socket.inet_ntoa(ip.dst)
    print "%s -> %s" % (src, dst)

To grab frames off the wire with pypcap:

    import pcap
    pc = pcap.pcapObject()
    dev = sys.argv[1]
    pc.open_live(dev, 1600, 0, 100)
    pc.setfilter("udp port 53", 0, 0)
    while 1:
        pc.dispatch(1, p.pcap_dispatch)

Of course, the two can be used together: (ripped from pypcap's homepage)

>>> import dpkt, pcap
>>> pc = pcap.pcap()
>>> pc.setfilter('icmp')
>>> for ts, pkt in pc:
...     print `dpkt.ethernet.Ethernet(pkt)`

Good luck!

这篇关于是否有用于 Wireshark 的 API 来开发与其交互/增强它的程序/插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆