Java Utililty Methods Host Check

List of utility methods to do Host Check

  1. HOME
  2. Java
  3. H
  4. Host Check

Description

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

Method

boolean checkHost(String host)
check Host
try {
 InetAddress.getByName(host);
 return (true);
} catch (UnknownHostException uhe) {
 return (false);
void checkHost(String hostname)
check Host
InetAddress.getByName(hostname);
InetAddress checkHostIsAvailable(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;
boolean checkHostName(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);
...
boolean isLocal(final String hostname)
is Local
try {
 return InetAddress.getByName(hostname).isLoopbackAddress();
} catch (UnknownHostException e) {
 return false;
boolean isLocal(final String hostName)
Checks if given host name is local.
try {
 return isLocal(InetAddress.getByName(hostName));
} catch (final UnknownHostException e) {
 return false;
boolean isHostReachable(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;
boolean isInternalHostname(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;
boolean isThisMe(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++) {
...
String normalizeHost(String host)
normalize Host
try {
 InetAddress address = InetAddress.getByName(host);
 if (isLocalAddress(address)) {
 return InetAddress.getLocalHost().getHostAddress();
 } else {
 return address.getHostAddress();
} catch (UnknownHostException e) {
...


AltStyle によって変換されたページ (->オリジナル) /