/*
Returns the InetAddress of this host
544688
protected InetAddress getLocalHost() {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.entering(methodClassName, methodNames[GET_LOCAL_HOST]);
        }
        if (mLocalHost == null) {
            synchronized (this) {
                try {
                    mLocalHost = (InetAddress) AccessController.doPrivileged(new PrivilegedExceptionAction()
                    {
                        @Override
                        public Object run() throws UnknownHostException
                    {
                        return InetAddress.getLocalHost();
                    }
                    });
                    if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                        LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, methodNames[GET_LOCAL_HOST], "InetAddress = " + mLocalHost);
                    }
                } catch (PrivilegedActionException pae) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(pae, "com.ibm.ws.session.SessionContext.getLocalHost", "423", this);
                    LoggingUtil.SESSION_LOGGER_CORE.logp(Level.SEVERE, methodClassName, methodNames[GET_LOCAL_HOST], "", pae);
                }
            }
        }
        return mLocalHost;
    }
15370
@Override
    public InetAddress getHostAddress(URL url) {
        try {
            return (InetAddress) _getHostAddress.invoke(getInstance(), new Object[] { url });
        } catch (Exception e) {
            FFDCFilter.processException(e, getClass().getName(), "getHostAddress", url);
            return null;
        }
    }
936137
public static String getIP(final InetAddress inetAddress)
	{
		String ip = "";
		ip = inetAddress.getHostAddress();
		if (ip.equals(""))
		{
			final byte[] ipAddressInBytes = inetAddress.getAddress();
			for (int i = 0; i < ipAddressInBytes.length; i++)
			{
				if (i > 0)
				{
					ip += ".";
				}
				ip += ipAddressInBytes[i] & 0xFF;
			}
		}
		return ip;
	}
1098411
private static InetAddress getLocalAddress() throws UnknownHostException {
    try {
      return InetAddress.getLocalHost();  // first NIC
    } catch (Exception ignore) {
      return InetAddress.getByName(null);
    }
  }
133646
public InetAddress
getAddress() {
	try {
		if (name == null)
			return InetAddress.getByAddress(address);
		else
			return InetAddress.getByAddress(name.toString(),
							address);
	} catch (UnknownHostException e) {
		return null;
	}
}
427580
public static InetAddress getLocalAddress() {
        InetAddress localAddress = null;
        try {
            localAddress = InetAddress.getLocalHost();
            if (isValidAddress(localAddress)) {
                return localAddress;
            }
        } catch (Throwable e) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Error when retrieving ip address: " + e.getMessage(), e);
            }
        }
        try {
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            if (interfaces != null) {
                while (interfaces.hasMoreElements()) {
                    try {
                        NetworkInterface network = interfaces.nextElement();
                        Enumeration<InetAddress> addresses = network.getInetAddresses();
                        while (addresses.hasMoreElements()) {
                            try {
                                InetAddress address = addresses.nextElement();
                                if (isValidAddress(address)) {
                                    return address;
                                }
                            } catch (Throwable e) {
                                if (LOGGER.isWarnEnabled()) {
                                    LOGGER.warn("Error when retrieving ip address: " + e.getMessage(), e);
                                }
                            }
                        }
                    } catch (Throwable e) {
                        if (LOGGER.isWarnEnabled()) {
                            LOGGER.warn("Error when retrieving ip address: " + e.getMessage(), e);
                        }
                    }
                }
            }
        } catch (Throwable e) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Error when retrieving ip address: " + e.getMessage(), e);
            }
        }
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Can't get valid host, will use 127.0.0.1 instead.");
        }
        return localAddress;
    }
32212
public static InetAddress getLocalIpAddress() throws RuntimeException
	{
		try
		{
			List<InetAddress> ips = getLocalIpAddresses(false, true);

			for (InetAddress ip : ips)
			{
				log.debug("[IpHelper] {getLocalIpAddress} Considering locality of " + ip.getHostAddress());
				if (!ip.isAnyLocalAddress() && (ip instanceof Inet4Address))
				{
					// Ubuntu sets the unix hostname to resolve to 127.0.1.1; this is annoying so treat it as a loopback
					if (!ip.getHostAddress().startsWith("127.0."))
					{
						log.debug("[IpHelper] {getLocalIpAddress} Found nonloopback IP: " + ip.getHostAddress());
						return ip;
					}
				}
			}

			log.trace("[IpHelper] {getLocalIpAddress} Couldn't find a public IP in the ip (size " + ips.size() + ")");
			return InetAddress.getLocalHost();
		}
		catch (UnknownHostException e)
		{
			throw new RuntimeException("[FileHelper] {getLocalIp}: Unable to acquire the current machine's InetAddress", e);
		}
	}
524637
public InetAddress []
lookupAllHostAddr(String host) throws UnknownHostException {
	Name name = null;

	try {
		name = new Name(host);
	}
	catch (TextParseException e) {
		throw new UnknownHostException(host);
	}

	Record [] records = null;
	if (preferV6)
		records = new Lookup(name, Type.AAAA).run();
	if (records == null)
		records = new Lookup(name, Type.A).run();
	if (records == null && !preferV6)
		records = new Lookup(name, Type.AAAA).run();
	if (records == null)
		throw new UnknownHostException(host);

	InetAddress[] array = new InetAddress[records.length];
	for (int i = 0; i < records.length; i++) {
		Record record = records[i];
		if (records[i] instanceof ARecord) {
			ARecord a = (ARecord) records[i];
			array[i] = a.getAddress();
		} else {
			AAAARecord aaaa = (AAAARecord) records[i];
			array[i] = aaaa.getAddress();
		}
	}
	return array;
}
1075844
public static InetAddress getAddress(String host) throws UnknownHostException {
        if (timeToClean()) {
            synchronized (storedAddresses) {
                if (timeToClean()) {
                    cleanOldAddresses();
                }
            }
        }
        Pair<InetAddress, Long> cachedAddress;
        synchronized (storedAddresses) {
            cachedAddress = storedAddresses.get(host);
        }
        if (cachedAddress != null) {
            //host DNS entry was cached
            InetAddress address = cachedAddress.getFirst();
            if (address == null) {
                throw new UnknownHostException("Could not find host " + host + " (cached response)");
            } else {
                return address;
            }
        } else {
            //host DNS entry was not cached
            fetchDnsAddressLock.acquireUninterruptibly();
            try {
                InetAddress addr = InetAddress.getByName(host);
                synchronized (storedAddresses) {
                    storedAddresses.put(host, new Pair<>(addr, System.currentTimeMillis()));
                }
                return addr;
            } catch (UnknownHostException exp) {
                synchronized (storedAddresses) {
                    storedAddresses.put(host, new Pair<InetAddress, Long>(null, System.currentTimeMillis()));
                }
                Log.i("[Dns lookup] " + host + " --> not found");
                throw exp;
            } finally {
                fetchDnsAddressLock.release();
            }

        }
    }
122365
public static InetAddress inetAddressFromLocation(String location) {
        try {
            return InetAddress.getByName(location);
        } catch (UnknownHostException e) {
            throw new DeepIOException(e);
        }
    }
1022381
function getHostname()
{
  var interfaces = networkInterfaces()
  for(var name in interfaces)
  {
    var info = interfaces[name].filter(filterIPv4)[0]
    if(info) return info.address
  }
}
135931
public static String getIpByHost(String hostName) {
		try {
			return InetAddress.getByName(hostName).getHostAddress();
		} catch (UnknownHostException e) {
			return hostName;
		}
	}
1362577
public String getHostAddress() {
        if( addr instanceof NbtAddress ) {
            return ((NbtAddress)addr).getHostAddress();
        }
        return ((InetAddress)addr).getHostAddress();
    }
744180
public static InetAddress getLocalAddress(Map<String, Integer> destHostPorts) {
        if (LOCAL_ADDRESS != null) {
            return LOCAL_ADDRESS;
        }

        InetAddress localAddress = getLocalAddressByHostname();
        if (!isValidAddress(localAddress)) {
            localAddress = getLocalAddressBySocket(destHostPorts);
        }

        if (!isValidAddress(localAddress)) {
            localAddress = getLocalAddressByNetworkInterface();
        }

        if (isValidAddress(localAddress)) {
            LOCAL_ADDRESS = localAddress;
        }

        return localAddress;
    }
1220992
public static InetAddress ntoa(final int address)
	{
		try
		{
			final byte[] addr = new byte[4];

			addr[0] = (byte) ((address >>> 24) & 0xFF);
			addr[1] = (byte) ((address >>> 16) & 0xFF);
			addr[2] = (byte) ((address >>> 8) & 0xFF);
			addr[3] = (byte) (address & 0xFF);

			return InetAddress.getByAddress(addr);
		}
		catch (UnknownHostException e)
		{
			// will never be thrown
			throw new Error(e);
		}
	}
981571
public static String getEthernetAddress() {

        try {
            InetAddress ip = InetAddress.getLocalHost();
            if (!ip.isLoopbackAddress()) {
                NetworkInterface network = NetworkInterface.getByInetAddress(ip);
                byte[] mac = network.getHardwareAddress();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < mac.length; i++) {
                    sb.append(String.format("%02X%s", new Byte(mac[i]), (i < (mac.length - 1)) ? ":" : ""));
                }
                return sb.toString();
            }
        } catch (Throwable t) {
            // if an exception occurred return a dummy address
        }
        // return a dummy ethernet address, if the ip is representing the loopback address or in case of exceptions
        return CmsUUID.getDummyEthernetAddress();
    }
329588
public static InetAddress getLocalHost() {

        if (localHost == null) {
            try {
                localHost = java.net.InetAddress.getLocalHost();
            } catch (UnknownHostException e) {
                LOGGER.error("Cannot get local host address. exception is: " + e);
                localHost = null;
                hostName = "UNKNOWN";
                ipAddress = "UNKNOWN";
            }
        }

        return localHost;

    }