CodesJava

Easy learning with example program codes

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.codesjava;
 
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

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status