The easiest way to get started with jNetPcap.
One dependency, everything included.
<dependency>
<groupId>com.slytechs.sdk</groupId>
<artifactId>jnetpcap-sdk</artifactId>
<version>3.0.0</version>
<type>pom</type>
</dependency><repositories>
<repository>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<dependency>
<groupId>com.slytechs.sdk</groupId>
<artifactId>jnetpcap-sdk</artifactId>
<version>3.1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>| Module | Description |
|---|---|
jnetpcap-api |
High-level capture and protocol dissection API |
jnetpcap-bindings |
Low-level libpcap FFM bindings (1:1 libpcap) |
sdk-protocol-core |
Packet, Header, dissection framework |
sdk-protocol-tcpip |
Ethernet, IPv4/IPv6, TCP, UDP, ICMP and more |
sdk-protocol-web |
HTTP, TLS, QUIC, HTTP/2, HTTP/3 |
sdk-common |
Memory management, pooling, utilities |
import com.slytechs.sdk.jnetpcap.api.NetPcap;
import com.slytechs.sdk.protocol.tcpip.ip.Ip4;
import com.slytechs.sdk.protocol.tcpip.tcp.Tcp;
try (var pcap = NetPcap.openOffline("capture.pcap")) {
Ip4 ip4 = new Ip4();
Tcp tcp = new Tcp();
pcap.dispatch(100, packet -> {
if (packet.hasHeader(ip4))
System.out.printf("IP: %s -> %s%n", ip4.src(), ip4.dst());
if (packet.hasHeader(tcp))
System.out.printf("TCP: %d -> %d%n", tcp.srcPort(), tcp.dstPort());
});
}No license calls required — the Community Edition activates automatically.
java --enable-native-access=com.slytechs.sdk.jnetpcap,com.slytechs.sdk.common \
-jar myapp.jartry (var pcap = NetPcap.create("eth0")) {
pcap.setSnaplen(65535)
.setPromisc(true)
.setTimeout(Duration.ofSeconds(1))
.activate();
pcap.setFilter("tcp port 443");
Ip4 ip4 = new Ip4();
pcap.loop(-1, packet -> {
if (packet.hasHeader(ip4))
System.out.println(ip4.src() + " -> " + ip4.dst());
});
}<!-- Web protocols: HTTP, TLS, QUIC, HTTP/2, HTTP/3 -->
<dependency>
<groupId>com.slytechs.sdk</groupId>
<artifactId>sdk-protocol-web</artifactId>
<version>3.0.0</version>
</dependency>| Platform | Library | Installation |
|---|---|---|
| Linux | libpcap | apt install libpcap-dev |
| macOS | libpcap | Pre-installed |
| Windows | Npcap | npcap.com |
repositories {
mavenCentral()
// For snapshots only:
maven { url 'https://central.sonatype.com/repository/maven-snapshots/' }
}
dependencies {
implementation 'com.slytechs.sdk:jnetpcap-sdk:3.0.0'
}See jnetpcap-examples for working examples covering:
- Live capture and offline file reading
- Protocol dissection (Ethernet, IP, TCP, HTTP, TLS)
- BPF filtering
- Packet dumping with
PcapDumper - Pooled zero-allocation capture
- Multi-threaded producer-consumer patterns
- Interface enumeration
- API Specification — Full API reference
- Javadocs — Generated API docs
- GitHub Wiki — Guides and tutorials
Licensed under the Apache License, Version 2.0.
The Community Edition includes telemetry. For commercial licenses without telemetry, contact sales@slytechs.com.
Sly Technologies Inc. — High-performance network analysis solutions