Java Programming

Ping Host

Java programming example for ping host

10/29/2021
0 views
ping-host.javaJava
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
Java TutorialPing HostPing Server

Related Examples