-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,85 @@ | ||
# packetdumper | ||
A kotlin / android compatible buffer / packet dumper to text and pcapnpg files long with a tcp | ||
pcapng server | ||
A kotlin / android compatible buffer / packet dumper. | ||
|
||
## Usage | ||
Add the dependency to your project (coming soon on maven central): | ||
``` | ||
implementation("com.jasonernst.packetdumper:packetdumper:<version>") | ||
``` | ||
|
||
### pcapng tcp server | ||
This will start a TCP server on port 19000 that will accept connections from wireshark as follows: | ||
`wireshark -k -i TCP@<ip>: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) | ||
``` | ||
|
||
## Currently supports: | ||
- [x] Basic buffer dumping capabilities to: | ||
- [x] hexdump stdout | ||
- [x] hexdump file (wireshark import compatible) | ||
- [x] hexdump string (for debugging) | ||
- [x] hexdump to slf4j logger | ||
- [x] pcapng file writing | ||
- [x] pcapng tcp server writing | ||
- [x] Tests + CI integration | ||
|
||
## TODO | ||
- [ ] Basic dumping capabilities | ||
- [ ] Tests + CI integration | ||
- [ ] Documentation + Examples | ||
- [ ] Release on Maven Central | ||
- [ ] Release on Maven Central | ||
- [ ] Support options for pcap blocks | ||
- [ ] Timestamps on enhanced packet blocks |