List of utility methods to do IP Address Get
String | getIPs() get I Ps try { Enumeration<NetworkInterface> nets; NetworkInterface n; Enumeration<InetAddress> addrs; InetAddress a; String s = ""; nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { ... |
String | getIPv4Address() get I Pv Address try { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); NetworkInterface itf = null; while (en.hasMoreElements()) { itf = en.nextElement(); if (!itf.isLoopback()) { Enumeration<InetAddress> addresses = itf.getInetAddresses(); InetAddress addr = null; ... |
String | getIPV4Address(List Finds an ipv4 address in a list of interface addresses for (InterfaceAddress interfaceAddress : addresses) { if (interfaceAddress.getAddress() instanceof Inet4Address) { return interfaceAddress.getAddress().getHostAddress(); return null; |
Inet4Address | getIPv4Address(NetworkInterface iface) get I Pv Address for (InterfaceAddress interfaceAddress : iface.getInterfaceAddresses()) { if (interfaceAddress.getAddress() instanceof Inet4Address) { return (Inet4Address) interfaceAddress.getAddress(); return null; |
Inet4Address | getIPV4MainAddress(NetworkInterface ni) Return the main ip V4 address associated with the ni Inet4Address[] addresses = getIPV4AllAddresses(ni); if (addresses != null && addresses.length > 0) { return addresses[addresses.length - 1]; return null; |
InetAddress | getIPv4MulticastGroup(int hash) get I Pv Multicast Group return getIPv4MulticastGroup(hash, IPV4_MULTICAST_ALLOCATION_RANGE[0], IPV4_MULTICAST_ALLOCATION_RANGE[1]);
|
byte[] | getIPV4NetwprkOrder(String theIp) turn ip in string representation to byte array in network order. byte[] toReturn = new byte[IPV4_ADDRESS_LEN]; String[] fields = theIp.split("\\."); if (fields == null || fields.length < IPV4_ADDRESS_LEN) { throw new UnknownHostException(); for (int i = 0; i < fields.length; i++) { toReturn[i] = (byte) Integer.parseInt(fields[i]); return toReturn; |
int[] | getIPV6AddrArray(String s) get IPV Addr Array try { InetAddress inetaddress = InetAddress.getByName(s); s = inetaddress.getHostAddress(); } catch (UnknownHostException unknownhostexception) { System.err.println("unknown ipv6 exception"); StringTokenizer stringtokenizer = new StringTokenizer(s, ":"); if (stringtokenizer.countTokens() != 8) ... |
Inet6Address[] | getIPV6AllAddresses(NetworkInterface ni) Return all the ip V6 addresses associated with the ni ArrayList<Inet6Address> v = new ArrayList<Inet6Address>(); for (Enumeration<InetAddress> e = ni.getInetAddresses(); e.hasMoreElements();) { InetAddress addr = e.nextElement(); if (addr instanceof Inet6Address) v.add((Inet6Address) addr); return v.toArray(new Inet6Address[v.size()]); |
List | getIpv6List() Get all IPv6 addresses defined in local network adapters. List<Inet6Address> addresses = new ArrayList<>(); try { for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis .hasMoreElements();) { NetworkInterface ni = nis.nextElement(); for (Enumeration<InetAddress> ias2 = ni.getInetAddresses(); ias2.hasMoreElements();) { InetAddress ia = ias2.nextElement(); if (ia instanceof Inet6Address) { ... |