- Notifications
You must be signed in to change notification settings - Fork4
Jxnet is a Java library for capturing and sending custom network packet buffers with no copies. Jxnet wraps a native packet capture library (libpcap/winpcap/npcap) via JNI (Java Native Interface).
License
jxnet/Jxnet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Jxnet is a Java library for capturing and sending custom network packet buffers with no copies.Jxnet wraps a native packet capture library (libpcap/npcap) via JNI (Java Native Interface).
- Lightweight (
jxnet-core
is around 160 KB in size) - Low lavel and asynchronous
event-driven
network application libarary - Easy to configure and integrated with popular java framework (
spring-boot
) - Using
direct buffer
(without copying buffer for minimized unnecessary memory copy) - Better
throughput
andlower latency
- Maintainable and Immutable (
thread-safe
) packet classes
- Windows 7/8/10 (x86/x86_64)
- Linux (x86/x86_64)
- Mac OS
- Java 8 (or newer)
- Windows
- Winpcap or Npcap
- Linux
- Libpcap
- Mac OS
- Libpcap
- Windows
List of supported protocol available atJxpacket.
Add a dependency to the pom.xml as like below:
<dependencies> <dependency> <groupId>com.ardikars.jxnet</groupId> <artifactId>jxnet-spring-boot-starter</artifactId> </dependency></dependencies><dependencyManagement> <dependencies> <dependency> <groupId>com.ardikars.jxnet</groupId> <artifactId>jxnet</artifactId> <version>1.4.9.Final</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
Add a dependency to the build.gradle as like below:
apply plugin: 'io.spring.dependency-management'dependencies { compile ("com.ardikars.jxnet:jxnet-spring-boot-starter")}dependencyManagement { imports { mavenBom("com.ardikars.jxnet:jxnet:1.4.9.Final") }}
@SpringBootApplicationpublicclassApplicationimplementsCommandLineRunner {publicstaticfinalintMAX_PACKET = -1;// infinite loopprivatestaticfinalLoggerLOGGER =LoggerFactory.getLogger(Application.class.getName());privateContextcontext;privatePcapIfpcapIf;privateMacAddressmacAddress;@AutowiredprivatePcapHandler<String>pcapHandler;publicApplication(Contextcontext,PcapIfpcapIf,MacAddressmacAddress) {this.context =context;this.pcapIf =pcapIf;this.macAddress =macAddress; }@Overridepublicvoidrun(String...args)throwsException {LOGGER.info("Network Interface : {}",pcapIf.getName());LOGGER.info("MAC Address : {}",macAddress);LOGGER.info("Addresses : ");for (PcapAddraddr :pcapIf.getAddresses()) {if (addr.getAddr().getSaFamily() ==SockAddr.Family.AF_INET) {LOGGER.info("\tAddress : {}",Inet4Address.valueOf(addr.getAddr().getData()));LOGGER.info("\tNetwork : {}",Inet4Address.valueOf(addr.getNetmask().getData())); } }context.pcapLoop(MAX_PACKET,pcapHandler,"Jxnet!"); }publicstaticvoidmain(String[]args) {SpringApplication.run(Application.class,args); }}
@EnablePacket@ConfigurationpublicclassDefaultJxpacketHandlerimplementsJxpacketHandler<String> {privatestaticfinalLoggerLOGGER =LoggerFactory.getLogger(DefaultJxpacketHandler.class.getName());privatestaticfinalStringPRETTY_FOOTER ="+---------------------------------------------------" +"--------------------------------------------------+";privatevoidprint(Pair<PcapPktHdr,Packet>packet) {Iterator<Packet>iterator =packet.getRight().iterator();LOGGER.info("Pcap packet header : {}",packet.getLeft());LOGGER.info("Packet header : ");while (iterator.hasNext()) {LOGGER.info("{}",iterator.next()); }LOGGER.info(PRETTY_FOOTER); }@Overridepublicvoidnext(Stringargument,Future<Pair<PcapPktHdr,Packet>>packet)throwsExecutionException,InterruptedException {LOGGER.info("User argument : {}",argument);print(packet.get()); }}
Property | Pcap Type | Default Value | Description |
---|---|---|---|
jxnet.source | LIVE | Auto selected | A device (source) used to create a pcap handle |
jxnet.snaphot | LIVE | 65535 | Dimension of the packet portion (in bytes) |
jxnet.promiscuous | LIVE | PROMISCUOUS | Pomiscuous mode |
jxnet.timeout | LIVE | 2000 | Packet buffer timeout |
jxnet.immediate | LIVE | IMMEDIATE | Immediate mode |
jxnet.timestampType | LIVE | HOST | Typestamp type |
jxnet.timestampPrecision | LIVE | MICRO | Typestamp precision |
jxnet.rfmon | LIVE | NON_RFMON | Radio frequency monitor mode |
jxnet.blocking | LIVE | false | Blocking mode |
jxnet.direction | LIVE | PCAP_D_INOUT | Specify a direction that packet will be captured |
jxnet.datalink | DEAD | 1 (Ethernet) | Datalink type |
jxnet.file | OFFLINE | null | Absulute path of pcap file |
jxnet.bpfCompileMode | LIVE | OPTIMIZE | Berkeley packet filter compile mode |
jxnet.filter | LIVE | null | Filtering expression syntax |
jxnet.pcapType | LIVE/OFFLINE/DEAD | LIVE | Pcap type (live/offline/dead) |
jxnet.numberOfThread | LIVE, OFFLINE | Depends on available processors | Number of pooled thread |
jxnet.jxpacket.autoRegister | LIVE, OFFLINE | false | Auto register jxpacket protocol |
- Install Mingw64 (SLJL) for cross compilation and add the path of the Mingw64
bin
directory to the environment variablePATH
. See.\.scripts\InstallMingw64.ps1
.
- Install Mingw64 (SLJL) for cross compilation and add the path of the Mingw64
- Install Gcc
- Install Libpcap-Dev, ex
# apt-get install libpcap-dev
on debian.
- Install Gcc/Clang/XCode
./gradlew clean build
./gradlew clean build -x test
- CMake
- Install Gcc & CMake & Make & Libpcap-Dev
mkdir jxnet-native/build && cd jxnet-native/build && cmake ../ && make
- Autotools
- Install Autoconf & Automake & Make & Libtool & Libpcap-Dev
cd jxnet-native/ && ./bootstrap.sh && ./configure && make
GNU Lesser General Public License, Version 3
/** * Copyright (C) 2015-2018 Jxnet * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */
Email: Ardika Rommy Sanjaya (contact@ardikars.com)
Have a bug or question? Please create an issuehere on Github!
About
Jxnet is a Java library for capturing and sending custom network packet buffers with no copies. Jxnet wraps a native packet capture library (libpcap/winpcap/npcap) via JNI (Java Native Interface).