how to get hostname from ip address in java?

The java.net.InetAddress class represents an IP address. It provides the methods to work with IP and host name.

Get hostname from ip address in java

package com.w3spoint;
 
import java.net.InetAddress;
 
public class NetworkTest {
  public static void main(String args[]){
	try {
	    InetAddress host = InetAddress.getByName("107.180.2.128");
            System.out.println(host.getHostName());
        } catch(Exception e) {
            e.printStackTrace();
        }
  }
}

Output

ip-107-180-2-128.ip.secureserver.net

Related topics

Content Protection by DMCA.com
Please Share