jnetpcap-wrapper
jnetpcap-wrapper copied to clipboard
jNetPcap v2, a libpcap network packet capture using powerful Java API on Linux, Windows, Mac, etc..
jNetPcap Wrapper
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].
Table of Contents
- Overview
- API Diagram
- Documentation
- Where are the protocols found in v1?
- Examples
- Capture a Live Packet
- Transmit a Packet With Data-Link Header
- Statistics Snapshots
- How To Run The Examples
- For More Examples
- Dependencies
- Java Dependencies
- Native Library Dependencies
- Installation
- Maven Artifact Config
- Using Latest SNAPSHOT Releases
- Download Release Package
- Compile From Source
- Contact
- Compatibility with jNetPcap Version 1
- Git Branches
- Javadocs API Documentation
Overview
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
Pcapclass for interface monitoring andPcapPacketHandlerfor efficient packet processing. - Precise Packet Filtering: Apply filters for targeted packet capture.
API Diagram
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]
Documentation
- Wiki pages: Comprehensive user guides and examples.
- Javadocs: Detailed API documentation.
Where are the protocols found in v1?
Protocol support from version 1 is now part of jnetpcap-sdk, extending the basic wrapper's functionality.
Examples
Capture a Live Packet
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");
}
}
Transmit a Packet With Data-Link Header
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);
}
}
Statistics Snapshots
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);
}
}
}
How To Run The Examples
Command-line Arguments:
- 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
Dependencies
Java Dependencies
No external dependencies apart from standard Java modules.
Native Library Dependencies
Requires libpcap, [Npcap][npcap], or [WinPcap][winpcap].
Installation
Maven Artifact Config
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>
Using Latest SNAPSHOT Releases
Add this repository:
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
Download Release Package
Latest release: download link
Contact
- Email:
[email protected]
Compatibility with jNetPcap Version 1
Details in the Wiki.
Git Branches
Follows a standard branching model.
Javadocs API Documentation
The Javadocs are automatically generated and deployed to the gh-pages branch for easy reference. Access the Javadocs here