Java Host Check isThisMe(String hostname)

Here you can find the source of isThisMe(String hostname)

Description

is This Me

License

Apache License

Declaration

private static boolean isThisMe(String hostname) 

Method Source Code

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

import java.net.InetAddress;

public class Main {
    private static boolean isThisMe(String hostname) {
        try {/*from  w w w.j a  v a  2s  .c  om*/
            InetAddress[] myadds = getHostAddresses();
            InetAddress[] theiradds = InetAddress.getAllByName(hostname);

            for (int i = 0; i < theiradds.length; i++) {
                if (theiradds[i].isLoopbackAddress()) {
                    return true;
                }

                for (int j = 0; j < myadds.length; j++) {
                    if (myadds[j].equals(theiradds[i])) {
                        return true;
                    }
                }
            }
        } catch (Exception e) {
        }

        return false;
    }

    public static InetAddress[] getHostAddresses() {
        try {
            String hname = getHostName();

            if (hname == null) {
                return null;
            }

            return InetAddress.getAllByName(hname);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. checkHostName(String hostName)
  2. isLocal(final String hostname)
  3. isLocal(final String hostName)
  4. isHostReachable(String host, int timeout)
  5. isInternalHostname(String host)
  6. normalizeHost(String host)
  7. normalizeHostName(String name)
  8. normalizeHostNames(Collection names)