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

ListarrayToList(final InetAddress[] addresses)
array To List
final List result = new ArrayList(addresses.length);
result.addAll(Arrays.asList(addresses));
return result;
booleancanTcpListen(InetAddress address, int port)
can Tcp Listen
try (ServerSocket ss = new ServerSocket(port, 0, address)) {
    return true;
} catch (IOException e) {
    return false;
booleancheckIPMatch(String ipTemplateList, InetAddress addr)
Checks if the passed IP address complies to a given pattern.
if (isIPv6(addr)) {
    return checkIPv6Match(ipTemplateList, addr.getHostAddress());
} else {
    return checkIPv4Match(ipTemplateList, addr.getHostAddress());
ListcreateRandomSocketAddressList(InetAddress bindAddress, int preferredPort, int minPort, int maxPort)
create Random Socket Address List
if (minPort < 1 || minPort > 65535) {
    throw new IllegalArgumentException("Minimum port is outside legal range (1-65535). min=" + minPort);
if (maxPort < minPort) {
    throw new IllegalArgumentException(
            "Maximum port is less than minimum port. max=" + maxPort + ", min=" + minPort);
if (maxPort > 65535) {
...
StringformatAddresses(List addresses)
Format a list of InetAddress.
StringBuffer sb = new StringBuffer();
for (InetAddress addr : addresses) {
    String name = addr.getHostName();
    String ip = addr.getHostAddress();
    if (sb.length() > 0)
        sb.append(" ");
    sb.append(name).append("|").append(ip);
return sb.toString();
ListgetInetAddressList(NetworkInterface netInterface)
get Inet Address List
List<String> inetAddressList = new ArrayList<String>();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
InetAddress ip = null;
while (addresses.hasMoreElements()) {
    ip = (InetAddress) addresses.nextElement();
    if (ip != null && ip instanceof Inet4Address) {
        inetAddressList.add(ip.getHostAddress());
return inetAddressList;
booleanis6to4(InetAddress addr)
isto
if (!(addr instanceof Inet6Address))
    return false;
byte[] bytes = addr.getAddress();
return bytes[0] == 0x20 && bytes[1] == 0x02;
booleanisAddressReachable(InetAddress address)
is Address Reachable
try {
    return address.isReachable(200);
} catch (IOException e) {
    return false;
booleanisAny(InetAddress ip)
Returns true if the passed InetAddress contains all zero
for (byte b : ip.getAddress()) {
    if (b != 0) {
        return false;
return true;
booleanisBroadcastAddress(InetAddress address)
A IPv4 Broadcast Address

http://tools.ietf.org/html/rfc919

return isBroadcastAddress(address.getAddress());