List of utility methods to do InetAddress Create
InetAddress | getSafeInetAddress(String name, JSONObject json) get Safe Inet Address String value = getSafeString(name, json); if (value == null) return null; try { return InetAddress.getByName(value); } catch (Exception e) { return null; |
InetAddress | getSourceAddressForDestination(InetAddress destination) get Source Address For Destination throw new UnsupportedOperationException("Not implemented yet."); |
Iterable extends InetAddress> | getSpecificAddresses(@Nonnull InetAddress in) get Specific Addresses if (!in.isAnyLocalAddress()) return Collections.singleton(in); List<InetAddress> out = new ArrayList<InetAddress>(); for (NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (iface.isLoopback()) continue; if (!iface.isUp()) continue; ... |
InetAddress | getSubnetPrefix(InetAddress ip, int maskLen) Given an IP address and a prefix network mask length, it returns the equivalent subnet prefix IP address Example: for ip = "172.28.30.254" and maskLen = 25 it will return "172.28.30.128" int bytes = maskLen / 8; int bits = maskLen % 8; byte modifiedByte; byte[] sn = ip.getAddress(); if (bits > 0) { modifiedByte = (byte) (sn[bytes] >> (8 - bits)); sn[bytes] = (byte) (modifiedByte << (8 - bits)); bytes++; ... |
String | getURI(String protocol, InetAddress host, int port) get URI String hostAddr = host.getHostAddress(); if (host instanceof Inet6Address) { if (hostAddr.lastIndexOf('%') >= 0) { hostAddr = hostAddr.substring(0, hostAddr.lastIndexOf('%')); hostAddr = "[" + hostAddr + "]"; return protocol + "://" + hostAddr + ":" + port; ... |