Java program to get Host Name by IP Address

In this program we will provide Ip address of the google and program will print the hostname of the provided IP address.

Get Host Name by IP Address program in Java

//program to get host name by ip address
import java.net.*;

public class GetHostName {
  public static void main(String args[]) throws Exception {
    InetAddress inetAddress = InetAddress.getByName("8.8.8.8");
    System.out.println("Host Name: " + inetAddress.getHostName());
  }
}

Output:

    Host Name: google-public-dns-a.google.com

Core Java Example Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.