Ping Host

import java.util.Scanner;

public class ping {
	public static void main(String[] argv) throws Exception {
		Scanner input = new Scanner(;
		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:
IP Address:
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!