Unlock Network Packet Analysis in Java with jNetPcap Wrapper.
jNetPcap Wrapper is a libpcap Java library. This is the version 2 release of the popular jNetPcap library, originally hosted on [SourceForge.net][sf.net].
- Overview
- API Diagram
- Documentation
- Where are the protocols found in v1?
- Examples
- Dependencies
- Installation
- Contact
- Compatibility with jNetPcap Version 1
- Git Branches
- Javadocs API Documentation
Harness the power of libpcap within your Java applications using jNetPcap Wrapper, a bridge granting seamless access to low-level network monitoring capabilities.
Key Features:
- Capture and Analyze Network Traffic: Real-time packet interception for detailed analysis.
- Streamlined Integration: Easily incorporate the library via Maven or manual classpath addition.
- Intuitive Java API: User-friendly Java interface for network data handling.
- Packet Capture and Handling: Utilize the
Pcap
class for interface monitoring andPcapPacketHandler
for efficient packet processing. - Precise Packet Filtering: Apply filters for targeted packet capture.
graph TD
A[Java Application] --> B[jnetpcap-wrapper]
B --> C[Panama/JEP-424 Foreign Function & Memory API]
C --> D[Libpcap / WinPcap / Npcap]
D --> E[Operating System]
E --> F[Network Drivers]
F --> G[Network Interface Cards]
- Wiki pages: Comprehensive user guides and examples.
- Javadocs: Detailed API documentation.
Protocol support from version 1 is now part of jnetpcap-sdk, extending the basic wrapper's functionality.
void main() throws PcapException {
List<PcapIf> devices = Pcap.findAllDevs();
try (Pcap pcap = Pcap.create(devices.get(0))) {
pcap.activate();
pcap.loop(1, (String msg, PcapHeader header, byte[] packet) -> {
System.out.println(msg);
}, "Capture Example");
}
}
void main() throws PcapException {
String rawPacket = "0026622f4787...";
byte[] packetBytes = PcapUtils.parseHexString(rawPacket);
List<PcapIf> devices = Pcap.findAllDevs();
try (Pcap pcap = Pcap.create(devices.get(0))) {
pcap.activate();
pcap.sendPacket(packetBytes);
}
}
void main() throws PcapException, InterruptedException {
List<PcapIf> devices = Pcap.findAllDevs();
try (Pcap pcap = Pcap.create(devices.get(0))) {
pcap.activate();
for (int i = 0; i < 5; i++) {
System.out.println(pcap.stats());
Thread.sleep(1000);
}
}
}
- Linux:
-Djava.library.path=/usr/lib/... --enable-native-access=org.jnetpcap --enable-preview
- Windows:
-Djava.library.path=C:\Windows\... --enable-native-access=org.jnetpcap --enable-preview
No external dependencies apart from standard Java modules.
Requires libpcap, [Npcap][npcap], or [WinPcap][winpcap].
Use the latest version variable in your pom.xml
for easy updates:
<properties>
<jnetpcap.version>LATEST</jnetpcap.version>
</properties>
<dependency>
<groupId>com.slytechs.jnet.jnetpcap</groupId>
<artifactId>jnetpcap-wrapper</artifactId>
<version>${jnetpcap.version}</version>
</dependency>
Add this repository:
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
Latest release: download link
- Email:
sales@slytechs.com
Details in the Wiki.
Follows a standard branching model.
The Javadocs are automatically generated and deployed to the gh-pages
branch for easy reference. Access the Javadocs here