ping ip address using socket programing in java

Solutions on MaxInterview for ping ip address using socket programing in java by the best coders in the world

showing results for - "ping ip address using socket programing in java"
Melina
24 Jun 2020
1            /* ............... START ............... */
2                
3import java.net.*;
4
5public class JavaPingExample {
6	public static void main(String[] args) {
7
8		try {
9			String ipAddress = "127.0.0.1";
10			InetAddress inet = InetAddress.getByName(ipAddress);
11			System.out.println("Sending Ping Request to " + ipAddress);
12			if (inet.isReachable(5000)) {
13				System.out.println(ipAddress + " is reachable.");
14			} else {
15				System.out.println(ipAddress + " NOT reachable.");
16			}
17		} catch (Exception e) {
18			System.out.println("Exception:" + e.getMessage());
19		}
20	}
21}
22
23                /* ............... END ............... */
24