Java IP Address Get getIpByHost(String hostName)

Here you can find the source of getIpByHost(String hostName)

Description

get Ip By Host

License

Apache License

Parameter

Parameter Description
hostName a parameter

Return

ip address or hostName if UnknownHostException

Declaration

public static String getIpByHost(String hostName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.*;

public class Main {
    /**/*  w  w w . j a  va2s.  com*/
     * @param hostName
     * @return ip address or hostName if UnknownHostException
     */
    public static String getIpByHost(String hostName) {
        try {
            return InetAddress.getByName(hostName).getHostAddress();
        } catch (UnknownHostException e) {
            return hostName;
        }
    }
}

Related

  1. getIPAddressFromBytes(byte[] bytes)
  2. getIPAddressFromNetworkInterface(String ifaceName)
  3. getIPAddressFromNetworkInterfaces()
  4. getIPAdresses()
  5. getIpByHost(String hostName)
  6. getIpByHost(String hostName)
  7. getIPByInterfaceName(String name)
  8. getIpByName(String name)
  9. getIpByNetworkInterfaceName(String name)