as stated in viralpatel, you can use Runtime.exec()
Below is an example
class pingTest { public static void main(String[] args) { String ip = "127.0.0.1"; String pingResult = ""; String pingCmd = "ping " + ip; try { Runtime r = Runtime.getRuntime(); Process p = r.exec(pingCmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); pingResult += inputLine; } in.close(); } catch (IOException e) { System.out.println(e); } } }
Output
Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Reply from 127.0.0.1: bytes=32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
send http://www.velocityreviews.com/forums/t146589-ping-class-java.html
source share