Java Utililty Methods InetAddress Check

List of utility methods to do InetAddress Check

Description

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

Method

booleanIsBusy(final InetAddress remote, int port)
Is Busy
try {
    Socket s = new Socket(remote, port);
    s.close();
    return true;
} catch (Exception e) {
    return false;
booleanisClassicAddress(InetAddress address)
Returns true if the given InetAddress is an IPv4 address
return address instanceof Inet4Address;
booleanisCommonSubnet(InetAddress address1, InetAddress address2)
Checks if two IP addresses belong to the same subnet
byte[] address1data = address1.getAddress();
byte[] address2data = address2.getAddress();
return address1data[0] == address2data[0] && address1data[1] == address2data[1]
        && address1data[2] == address2data[2];
booleanisGlobalAddressV6(InetAddress addr)
checks if the provided address is a global-scope ipv6 unicast address
return addr instanceof Inet6Address && !addr.isAnyLocalAddress() && !addr.isLinkLocalAddress()
        && !addr.isLoopbackAddress() && !addr.isMulticastAddress() && !addr.isSiteLocalAddress()
        && !((Inet6Address) addr).isIPv4CompatibleAddress();
booleanisHostLocalHost(InetAddress host)
is Host Local Host
try {
    return getLocalAddress().equals(host);
} catch (UnknownHostException e) {
    return false;
booleanisInet6Compatible(InetAddress address, Inet6Address inet6Address)
is Inet Compatible
if (!(address instanceof Inet6Address)) {
    return false;
if (!Arrays.equals(address.getAddress(), inet6Address.getAddress())) {
    return false;
return true;
booleanisInRage(InetAddress check, InetAddress bcast, int netmask)
is In Rage
int byts = netmask / 8;
byte mask = (byte) ~(0xff >>> (netmask % 8));
byte[] b1 = check.getAddress();
byte[] b2 = bcast.getAddress();
int i;
for (i = 0; i < byts; i++) {
    if (b1[i] != b2[i]) {
        return false;
...
booleanisIpAddressInRange(InetAddress ipStart, InetAddress ipEnd, InetAddress ipToCheck)
is Ip Address In Range
long ipLo = inetAddressToLong(ipStart);
long ipHi = inetAddressToLong(ipEnd);
long ipToTest = inetAddressToLong(ipToCheck);
return (ipToTest >= ipLo && ipToTest <= ipHi);
booleanisIPLocal(final InetAddress adr)
is IP Local
return adr.isLinkLocalAddress() || adr.isLoopbackAddress() || adr.isSiteLocalAddress();
booleanisIPv6(final InetAddress ip)
True if this InetAddress is a raw IPv6 in dotted quad notation.
return ip instanceof Inet6Address && ip.getHostName().equals(ip.getHostAddress());