Skip to content

vimukthiD/jnb-ping

 
 

Repository files navigation

jnb-ping - Java Non-Blocking ICMP Ping

A non-blocking ICMP library for Java, using JNA to access native APIs, supporting thousands of simultaneous ICMP ping targets. Written in Kotlin, but compatible with Java (or any JVM-hosted language).

Currently, only Linux and MacOS X are supported.

Example (Kotlin):

class PingHandler : PingResponseHandler {
   override fun onResponse(pingTarget: PingTarget, responseTimeSec: Double, byteCount: Int, seq: Int) {
      System.out.printf("  ${Thread.currentThread()} $byteCount bytes from $pingTarget: icmp_seq=$seq time=%1.6f\n", responseTimeSec)
   }

   override fun onTimeout(pingTarget: PingTarget) {
      System.out.println("  ${Thread.currentThread()} Timeout $pingTarget")
   }
}

val pinger = IcmpPinger(PingHandler())

Thread( { pinger.runSelector() } ).start()

pinger.ping( PingTarget(InetAddress.getByName("8.8.8.8")) )
pinger.ping( PingTarget(InetAddress.getByName("youtube.com")) )

while (pinger.isPendingWork()) Thread.sleep(500)

pinger.stopSelector()

The minimum supported Linux kernel version is v4.19.10. It may work with older kernels (some reported working on v3.13.), depending on the kernel configuration parameters, but only v4.19.10+ has been tested. I am fairly certain that IPv6 is not supported (by this library) on any Linux kernel version less than v4.19.

About

Java Non-Blocking Ping (ICMP)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 85.2%
  • Starlark 14.8%