Java Utililty Methods Local Host Get

List of utility methods to do Local Host Get

Description

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

Method

ListgetLocalHosts()
Get host IP address
List<String> list = new ArrayList<>();
try {
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    while (nets.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) nets.nextElement();
        Enumeration<InetAddress> itor = ni.getInetAddresses();
        while (itor.hasMoreElements()) {
            InetAddress inetAddress = itor.nextElement();
...
booleanisLocalHost(String address)
Indica si la direccion IP/host que se pasa como parametro pertenece a la maquina local o no
if ((address == null) || (address.equals(""))) {
    return false;
try {
    InetAddress ia = InetAddress.getByName(address);
    if (ia.isLoopbackAddress()) {
        return true;
    NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
    return ni != null;
} catch (SocketException se) {
    return false;
} catch (UnknownHostException uhe) {
    return false;
booleanisLocalHost(String h1)
is Local Host
boolean ret = false;
try {
    InetAddress a1 = InetAddress.getByName(h1);
    if (a1 != null)
        ret = InetAddress.getLocalHost().getHostAddress().equals(a1.getHostAddress());
} catch (UnknownHostException e) {
return ret;
...
booleanisLocalhost(String host)
is Localhost
InetAddress address;
try {
    address = InetAddress.getByName(host);
} catch (UnknownHostException e) {
    return false;
if (address.isAnyLocalAddress() || address.isLoopbackAddress())
    return true;
...
booleanisLocalhost(String hostname)
Check if a hostname is the local host.
assert null != hostname : "hostname to check cannot be null!";
boolean isLocalhost = false;
try {
    InetAddress remoteHost = InetAddress.getByName(hostname);
    InetAddress localHost = InetAddress.getLocalHost();
    InetAddress loopback = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
    if (remoteHost.equals(localHost) || remoteHost.equals(loopback)) {
        isLocalhost = true;
...
booleanisLocalhost(String someHost)
is Localhost
if (null == someHost) {
    return false;
try {
    InetAddress localHostAddr = InetAddress.getLocalHost();
    InetAddress someAddr = InetAddress.getByName(someHost);
    return localHostAddr.equals(someAddr);
} catch (UnknownHostException uhe) {
...
booleanisLocalHostNameInList(String[] hostList)
is Local Host Name In List
String localHostName = getLocalHostName();
if (localHostName == null) {
    return false;
for (String host : hostList) {
    if (host.equalsIgnoreCase(localHostName)) {
        return true;
return false;