Java Program to Get Host Name by IP Address

You are currently viewing Java Program to Get Host Name by IP Address

Java program to get Host Name by IP Address

//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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply