Git Product home page Git Product logo

xorgx304 / jxnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jxnet/jxnet

0.0 1.0 0.0 15.2 MB

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

Home Page: http://ardikars.com

License: GNU Lesser General Public License v3.0

Java 99.08% Shell 0.66% Makefile 0.26%

jxnet's Introduction

Jxnet

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 Badge Build status Coverage Status

Download

Features

  • 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 and lower 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 at Jxpacket.

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.5.4.RELEASE</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.5.4.RELEASE") }
}
  • Example Application
@SpringBootApplication
public class Application extends AbstractJxnetApplicationRunner<String>  {
    
    public static final int MAX_PACKET = -1; // infinite loop
    
    @Override
    public void run(String... args) throws Exception {
        showSystemInfo();
        showNetworkInfo();
        loop(MAX_PACKET, "Jxnet!");
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
  • Pcap Packet Handler Configuration
@EnablePacket
@Configuration
public class DefaultJxpacketHandler implements JxpacketHandler<String> {

    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJxpacketHandler.class.getName());

    private static final String PRETTY_FOOTER = "+---------------------------------------------------"
            + "--------------------------------------------------+";

    private void print(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);
    }

    @Override
    public void next(String argument, Future<Pair<PcapPktHdr, Packet>> packet) throws ExecutionException, InterruptedException {
        LOGGER.info("User argument      : {}", argument);
        print(packet.get());
    }

}
  • Spring properties (Optional)

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

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 Mingw64 bin directory to the environment variable PATH. 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

  • Gradle
    • ./gradlew -p jxnet-native clean build
  • 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/>.
 */

Issues

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

jxnet's People

Contributors

agafox avatar ardikars avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.