List of utility methods to do InetAddress Check
List | arrayToList(final InetAddress[] addresses) array To List final List result = new ArrayList(addresses.length); result.addAll(Arrays.asList(addresses)); return result; |
boolean | canTcpListen(InetAddress address, int port) can Tcp Listen try (ServerSocket ss = new ServerSocket(port, 0, address)) { return true; } catch (IOException e) { return false; |
boolean | checkIPMatch(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()); |
List | createRandomSocketAddressList(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) { ... |
String | formatAddresses(List extends InetAddress> 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(); |
List | getInetAddressList(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; |
boolean | is6to4(InetAddress addr) isto if (!(addr instanceof Inet6Address)) return false; byte[] bytes = addr.getAddress(); return bytes[0] == 0x20 && bytes[1] == 0x02; |
boolean | isAddressReachable(InetAddress address) is Address Reachable try { return address.isReachable(200); } catch (IOException e) { return false; |
boolean | isAny(InetAddress ip) Returns true if the passed InetAddress contains all zero for (byte b : ip.getAddress()) { if (b != 0) { return false; return true; |
boolean | isBroadcastAddress(InetAddress address) A IPv4 Broadcast Address http://tools.ietf.org/html/rfc919 return isBroadcastAddress(address.getAddress());
|