Java Utililty Methods Host Check

List of utility methods to do Host Check

Description

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

Method

booleancheckHost(String host)
check Host
try {
    InetAddress.getByName(host);
    return (true);
} catch (UnknownHostException uhe) {
    return (false);
voidcheckHost(String hostname)
check Host
InetAddress.getByName(hostname);
InetAddresscheckHostIsAvailable(String hostName)
check Host Is Available
try {
    InetAddress hostAddr = InetAddress.getByName(hostName.trim());
    return hostAddr;
} catch (UnknownHostException e) {
    System.out.println("Unknow host error for host " + hostName + ": " + e);
    return null;
booleancheckHostName(String hostName)
Check if the host name is the given one.
if (hostName == null) {
    System.err.println("Given HOST name was NULL");
    return false;
try {
    String localHost = InetAddress.getLocalHost().getHostName();
    Pattern regex = Pattern.compile(hostName, Pattern.CASE_INSENSITIVE);
    Matcher regexMatcher = regex.matcher(localHost);
...
booleanisLocal(final String hostname)
is Local
try {
    return InetAddress.getByName(hostname).isLoopbackAddress();
} catch (UnknownHostException e) {
    return false;
booleanisLocal(final String hostName)
Checks if given host name is local.
try {
    return isLocal(InetAddress.getByName(hostName));
} catch (final UnknownHostException e) {
    return false;
booleanisHostReachable(String host, int timeout)
Get a value indicating whether the specified host is reachable using the specified timeout.
try {
    return InetAddress.getByName(host).isReachable(timeout);
} catch (IOException e) {
    return false;
booleanisInternalHostname(String host)
Checks if a host name is internal
try {
    InetAddress addr = InetAddress.getByName(host);
    return addr.isSiteLocalAddress() || addr.isLoopbackAddress();
} catch (UnknownHostException e) {
    e.printStackTrace();
return false;
booleanisThisMe(String hostname)
is This Me
try {
    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++) {
...
StringnormalizeHost(String host)
normalize Host
try {
    InetAddress address = InetAddress.getByName(host);
    if (isLocalAddress(address)) {
        return InetAddress.getLocalHost().getHostAddress();
    } else {
        return address.getHostAddress();
} catch (UnknownHostException e) {
...