Ping IP Address In Java Example

Chapter: Networking Last Updated: 21-09-2018 15:37:53 UTC

Program:

            /* ............... START ............... */
                
import java.net.*;

public class JavaPingExample {
	public static void main(String[] args) {

		try {
			String ipAddress = "127.0.0.1";
			InetAddress inet = InetAddress.getByName(ipAddress);
			System.out.println("Sending Ping Request to " + ipAddress);
			if (inet.isReachable(5000)) {
				System.out.println(ipAddress + " is reachable.");
			} else {
				System.out.println(ipAddress + " NOT reachable.");
			}
		} catch (Exception e) {
			System.out.println("Exception:" + e.getMessage());
		}
	}
}

                /* ............... END ............... */
        

Output

Sending Ping Request to 127.0.0.1
127.0.0.1 is reachable.

Notes:

  • The Ping command allows you to test the connection speed between you and another network node. You can use it to tell the strength, distance, and availability of a connection, either in your own network or over the internet.
  • Syntax : public static InetAddress getByName(String host) throws UnknownHostException.
  • In the program InetAddress.getByName(ipAddress) returns the instance of InetAddress containing LocalHost IP and name.
  • inet.isReachable is used to ping IP Address.

Tags

Java Ping IP Address , java ping library, java 8 ping, ping program in java source code, java socket ping, java ping url

Similar Programs Chapter Last Updated
Java URL Parts Example Networking 28-10-2016
Java Program To Create Socket At Specific Port Networking 28-10-2016
Java Find Proxy Settings Networking 10-09-2016
Java Download Webpage Example Networking 09-09-2016
Java URL Connection Date Networking 09-09-2016
Java Socket To Single Client Networking 09-09-2016
Java Server File Size Example Networking 09-09-2016
Java Multithreaded Server Example Networking 09-09-2016
Java Server File Modification Time Networking 09-09-2016
Java Connect To Server Example Networking 09-09-2016
Http Response Header In Java Example Networking 21-06-2016
Server Socket In Java Example Networking 30-04-2016
Socket Programming In Java Networking 30-04-2016
IP Address And HostName Of Local Computer In Java Networking 30-04-2016
HostName And IP Address In Java Networking 30-04-2016
Client Socket In Java Example Networking 30-04-2016
Read And Download Webpage In Java Example Networking 29-04-2016
Date Of URL Connection In Java Example Networking 29-04-2016
Who Is Lookup In Java Example Networking 21-07-2016
System Proxy In Java Example Networking 21-09-2018
Port Scanner In Java Example Networking 21-07-2016
MAC Address In Java Example Networking 22-09-2018
Get IP Address In Java Example Networking 07-04-2016
URL Properties In Java Example Networking 09-09-2016
Default URL Object In Java Example Networking 18-07-2016

1