Get Website Learn Coding Tech Story

Java Programming Examples

import java.io.*;
import java.util.Scanner;
import java.net.InetAddress;

public class ping {
	public static void main(String[] argv) throws Exception {
		Scanner input = new Scanner(System.in);
		System.out.println("Please enter a hostname:");
		InetAddress address = InetAddress.getByName(input.nextLine());
		System.out.println("Name: " + address.getHostName());
		System.out.println("IP Address: " + address.getHostAddress());

		/* Test whether that address is reachable using ping */
		System.out.println("Reachable: " + address.isReachable(10000));
	}
}


          /****** Output ******/
          

Please enter a hostname:


www.geekboots.com


Name: www.geekboots.com


IP Address: 103.21.58.244


Reachable: true

Learn more about isReachable