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