Lightweight libpcap Java (JNI) wrapper.
- pcap-java uses JNI to interact with the native stuff, while other libraries use JNA.
Sample code:
Pcap.init();
PcapHandle handle = Pcap.openLive("any", 120, 1, 10);
PcapDumper dumper = handle.dumpOpen("dump.pcap");
BpfProgram filter = handle.compile("tcp and dst port 80");
handle.setFilter(filter);
filter.free();
LinkType datalink = this.handle.datalink();
new Thread(() -> {
try {
this.handle.loop(-1, (packetHeader, rawPacket) -> {
try {
Packet packet = new Packet();
packet.decode(rawPacket, datalink);
System.out.println(packet);
dumper.dump(packetHeader, rawPacket);
dumper.flush();
} catch (LayerDecodeException | PcapException e) {
e.printStackTrace();
}
});
} catch (PcapException e) {
e.printStackTrace();
}
});
dumper.close();
handle.close();
- Maven:
<repositories>
<repository>
<id>elytrium-repo</id>
<url>https://maven.elytrium.net/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.elytrium</groupId>
<artifactId>pcap</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
- Gradle:
repositories {
maven {
setName("elytrium-repo")
setUrl("https://maven.elytrium.net/repo/")
}
}
dependencies {
implementation("net.elytrium:pcap:1.0.1")
}
- LimboFilter TCP Listener - Another code example.
Your donations are really appreciated. Donations wallets/links/cards: