Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
/JxnetPublic archive

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

NotificationsYou must be signed in to change notification settings

jxnet/Jxnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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).

Codacy BadgeBuild status

Download

Features

  • Lightweight (jxnet-core is around 160 KB in size)
  • Low lavel and asynchronousevent-driven network application libarary
  • Easy to configure and integrated with popular java framework (spring-boot)
  • Usingdirect buffer (without copying buffer for minimized unnecessary memory copy)
  • Betterthroughput andlower latency
  • Maintainable and Immutable (thread-safe) packet classes

Getting Started

Prerequisites

  • Platforms
    • Windows 7/8/10 (x86/x86_64)
    • Linux (x86/x86_64)
    • Mac OS
  • Java Version
    • Java 8 (or newer)
  • Dependecies
    • Windows
      • Winpcap or Npcap
    • Linux
      • Libpcap
    • Mac OS
      • Libpcap

Supported Protocol

List of supported protocol available atJxpacket.

How to Use

  • Maven project

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>
  • Gradle project

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") }}
  • Example Application
@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);    }}
  • Pcap Packet Handler Configuration
@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());    }}
  • Spring properties (Optional)

PropertyPcap TypeDefault ValueDescription
jxnet.sourceLIVEAuto selectedA device (source) used to create a pcap handle
jxnet.snaphotLIVE65535Dimension of the packet portion (in bytes)
jxnet.promiscuousLIVEPROMISCUOUSPomiscuous mode
jxnet.timeoutLIVE2000Packet buffer timeout
jxnet.immediateLIVEIMMEDIATEImmediate mode
jxnet.timestampTypeLIVEHOSTTypestamp type
jxnet.timestampPrecisionLIVEMICROTypestamp precision
jxnet.rfmonLIVENON_RFMONRadio frequency monitor mode
jxnet.blockingLIVEfalseBlocking mode
jxnet.directionLIVEPCAP_D_INOUTSpecify a direction that packet will be captured
jxnet.datalinkDEAD1 (Ethernet)Datalink type
jxnet.fileOFFLINEnullAbsulute path of pcap file
jxnet.bpfCompileModeLIVEOPTIMIZEBerkeley packet filter compile mode
jxnet.filterLIVEnullFiltering expression syntax
jxnet.pcapTypeLIVE/OFFLINE/DEADLIVEPcap type (live/offline/dead)
jxnet.numberOfThreadLIVE, OFFLINEDepends on available processorsNumber of pooled thread
jxnet.jxpacket.autoRegisterLIVE, OFFLINEfalseAuto register jxpacket protocol

Build Jxnet from Source

Setup Development Environment (JDK 1.8)

  • Windows (x86_64)
    • Install Mingw64 (SLJL) for cross compilation and add the path of the Mingw64bin directory to the environment variablePATH. See.\.scripts\InstallMingw64.ps1.
  • Linux
    • Install Gcc
    • Install Libpcap-Dev, ex# apt-get install libpcap-dev on debian.
  • Mac OS
    • Install Gcc/Clang/XCode

Build

  • ./gradlew clean build

Skip Test

  • ./gradlew clean build -x test

Build Only Native Shared Library

  • 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

License

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/>. */

Contact

Email: Ardika Rommy Sanjaya (contact@ardikars.com)

Issues

Have a bug or question? Please create an issuehere on Github!


[8]ページ先頭

©2009-2025 Movatter.jp