Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/compscidr/packetdumper
A kotlin / android compatible buffer / packet dumper which can output pcapng files, hex files, strings, and logging compatible with wireshark import, and a tcp server which serves wiresharp pcapng dumps live
https://github.com/compscidr/packetdumper
buffers dumper hacktoberfest kotlin packets pcap pcapng pcapng-decoder pcapng-files wireshark
Last synced: about 1 month ago
JSON representation
A kotlin / android compatible buffer / packet dumper which can output pcapng files, hex files, strings, and logging compatible with wireshark import, and a tcp server which serves wiresharp pcapng dumps live
- Host: GitHub
- URL: https://github.com/compscidr/packetdumper
- Owner: compscidr
- License: gpl-3.0
- Created: 2024-08-07T21:11:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T01:03:32.000Z (2 months ago)
- Last Synced: 2024-10-24T12:26:34.128Z (2 months ago)
- Topics: buffers, dumper, hacktoberfest, kotlin, packets, pcap, pcapng, pcapng-decoder, pcapng-files, wireshark
- Language: Kotlin
- Homepage:
- Size: 355 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# packetdumper
[![Maven Central](https://img.shields.io/maven-central/v/com.jasonernst.packetdumper/packetdumper?style=flat&logo=maven&label=maven-central&color=blue)](https://central.sonatype.com/artifact/com.jasonernst.packetdumper/packetdumper/overview)
[![codecov](https://codecov.io/gh/compscidr/packetdumper/graph/badge.svg?token=MZjRWQKz26)](https://codecov.io/gh/compscidr/packetdumper)A kotlin / android compatible buffer / packet dumper.
## Usage
Add the dependency to your project:
```
implementation("com.jasonernst.packetdumper:packetdumper:")
```### pcapng tcp server
This will start a TCP server on port 19000 that will accept connections from wireshark as follows:`wireshark -k -i TCP@:19000`
```kotlin
val dumper = PcapNgTcpServerPacketDumper()
dumper.start()
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
dumper.dumpBuffer(buffer, 0, buffer.limit(), false, null)// ...
dumper.stop()
```### pcapng file
Note that the file will actually be created with timestamps in the filename so that multiple runs
will not overwrite each other.
```kotlin
val dumper = PcapNgFilePacketDumper("/tmp", "test", "pcapng")
dumper.open()
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
dumper.dumpBuffer(buffer, 0, buffer.limit(), false, null)
dumper.close()
```### hexdump to file
The following will dump in a format which is compatible with a wireshark hexdump import.
This assumes that the buffer contains an ipv4 packet. If your buffer has an ethernet frame already
just leave this as null.
```kotlin
val dumper = TextFilePacketDumper("/tmp", "test", "txt")
dumper.open()
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
dumper.dumpBuffer(buffer, 0, buffer.limit(), true, EtherType.IPv4)
dumper.close()
```### hexdump to stdout
```kotlin
val dumper = StringPacketDumper(writeToStdOut = true)
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
dumper.dumpBuffer(buffer, 0, buffer.limit(), true, EtherType.IPv4)
```### hexdump to slf4j logger
This will log at the info level to the slf4j logger provided.
```kotlin
val logger = LoggerFactor.getLogger("somelogger")
val dumper = StringPacketDumper(logger)
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
dumper.dumpBuffer(buffer, 0, buffer.limit(), true, EtherType.IPv4)
```### hexdump to string
```kotlin
val dumper = StringPacketDumper()
val buffer = ByteBuffer.wrap(byteArrayOf(0x01, 0x02, 0x03, 0x04))
val hexString = dumper.dumpBufferToString(buffer, 0, buffer.limit(), true, EtherType.IPv4)
println(hexString)
```## TODO
- [ ] Support options for pcap blocks