Fri Oct 29 2021
Ping Host
Java Programming846 views
File Name: ping-host.java
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
Reference:
Author:Geekboots