Ping Host

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: 104.28.11.98
Reachable: true

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!