Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an API for Wireshark, to develop programs/plugins that interact with it/enhance it? [closed]

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.

like image 572
jim Avatar asked Feb 04 '10 10:02

jim


People also ask

What is Wireshark plugin?

Wireshark is a an application that analyzes packets from a network and displays the packet information in detail. Contrail Networking Release 2008 and later supports the Wireshark agent_header. lua plugin, which enables you to capture and analyze the packets exchanged between a vRouter data plane and vRouter agent.

What is the difference between Wireshark and TShark?

TShark is a terminal oriented version of Wireshark designed for capturing and displaying packets when an interactive user interface isn't necessary or available. It supports the same options as wireshark . For more information on tshark consult your local manual page ( man tshark ) or the online version.

Does Wireshark manipulate the network?

Wireshark is a packet sniffer and analysis tool. It captures network traffic on the local network and stores that data for offline analysis. Wireshark captures network traffic from Ethernet, Bluetooth, Wireless (IEEE. 802.11), Token Ring, Frame Relay connections, and more.


1 Answers

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!

like image 61
J.J. Avatar answered Oct 06 '22 01:10

J.J.