Java Utililty Methods Host Address Get

List of utility methods to do Host Address Get

Description

The list of methods to do Host Address Get are organized into topic(s).

Method

StringgetHostAddress(boolean promiscuous)
Returns the string "127.0.0.1".
String addr = "127.0.0.1";
try {
    if (JAVABRIDGE_PROMISCUOUS || promiscuous)
        addr = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
return addr;
StringgetHostAddress(final String name)
Return the local host address for a passed in host using java.net.InetAddress#getByName(String)
return InetAddress.getByName(name).getHostAddress();
InetAddressgetHostAddress(String hostname)
Get the Inet address of the machine of the given host name.
InetAddress serverIPAddress;
if (hostname != null && !hostname.isEmpty()) {
    serverIPAddress = InetAddress.getByName(hostname);
} else {
    serverIPAddress = InetAddress.getLocalHost();
return serverIPAddress;
InetAddressgetHostAddress(String hostPort)
Gets the host name from a host:port.
String host = getHost(hostPort);
return (host == null) ? null : InetAddress.getByName(host);
InetAddress[]getHostAddresses()
get Host Addresses
try {
    String hname = getHostName();
    if (hname == null) {
        return null;
    return InetAddress.getAllByName(hname);
} catch (Exception e) {
    return null;
...
String[]getHostAddresses()
get Host Addresses
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
List<String> hostIps = new ArrayList<String>();
while (nifs.hasMoreElements()) {
    NetworkInterface nif = (NetworkInterface) nifs.nextElement();
    Enumeration<InetAddress> ips = nif.getInetAddresses();
    while (ips.hasMoreElements()) {
        InetAddress ip = (InetAddress) ips.nextElement();
        if (ip instanceof java.net.Inet4Address) {
...
ListgetHostAddresses()
get Host Addresses
List<String> result = new ArrayList<>();
Enumeration e = NetworkInterface.getNetworkInterfaces();
while (e.hasMoreElements()) {
    NetworkInterface n = (NetworkInterface) e.nextElement();
    Enumeration ee = n.getInetAddresses();
    while (ee.hasMoreElements()) {
        InetAddress i = (InetAddress) ee.nextElement();
        if (i instanceof Inet6Address || i
...
StringgetHostAddressFromProperty(final String property)
Return the local host address based on the value of a system property.
return getInetAddressFromProperty(property).getHostAddress();
StringgetHostExternalAddr()
get Host External Addr
try {
    Enumeration e = NetworkInterface.getNetworkInterfaces();
    while (e.hasMoreElements()) {
        NetworkInterface n = (NetworkInterface) e.nextElement();
        Enumeration ee = n.getInetAddresses();
        while (ee.hasMoreElements()) {
            InetAddress i = (InetAddress) ee.nextElement();
            if (!i.getHostAddress().startsWith("192") && !i.getHostAddress().startsWith("127")) {
...
StringgetHostName(String addr)
get Host Name
if (!isRawAddress(addr))
    return addr;
try {
    return InetAddress.getByAddress(toRawAddress(addr)).getHostName();
} catch (UnknownHostException e) {
    return addr;