/** * Gets display name of the network interface this IP address belongs to. * * @param addr IP address for which to find network interface name. * @return Network interface name or {@code null} if can't be found. */ @Nullable public static String getNetworkInterfaceName(String addr) { assert addr != null; try { InetAddress inetAddr = InetAddress.getByName(addr); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) for (InetAddress itfAddr : asIterable(itf.getInetAddresses())) if (itfAddr.equals(inetAddr)) return itf.getDisplayName(); } catch (UnknownHostException ignore) { return null; } catch (SocketException ignore) { return null; } return null; }
/** * Gets a list of all local non-loopback IPs known to this JVM. * Note that this will include both IPv4 and IPv6 addresses (even if one "resolves" * into another). Loopbacks will be skipped. * * @return List of all known local IPs (empty list if no addresses available). */ public static synchronized Collection<String> allLocalIps() { List<String> ips = new ArrayList<>(4); try { Enumeration<NetworkInterface> itfs = NetworkInterface.getNetworkInterfaces(); if (itfs != null) { for (NetworkInterface itf : asIterable(itfs)) { if (!itf.isLoopback()) { Enumeration<InetAddress> addrs = itf.getInetAddresses(); for (InetAddress addr : asIterable(addrs)) { String hostAddr = addr.getHostAddress(); if (!addr.isLoopbackAddress() && !ips.contains(hostAddr)) ips.add(hostAddr); } } } } } catch (SocketException ignore) { return Collections.emptyList(); } Collections.sort(ips); return ips; }
for (NetworkInterface itf : asIterable(itfs)) { byte[] hwAddr = itf.getHardwareAddress();
List<NetworkInterface> itfs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) itfs.add(itf); boolean found = false; for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLoopbackAddress() && !addr.isLinkLocalAddress() && reachable(itf, addr, reachTimeout)) { locHost = addr;
zip = new ZipFile(zipFile); for (ZipEntry entry : asIterable(zip.entries())) { if (entry.isDirectory()) {
List<InetAddress> locAddrs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) { for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLinkLocalAddress()) locAddrs.add(addr);
/** * Gets a list of all local non-loopback IPs known to this JVM. * Note that this will include both IPv4 and IPv6 addresses (even if one "resolves" * into another). Loopbacks will be skipped. * * @return List of all known local IPs (empty list if no addresses available). */ public static synchronized Collection<String> allLocalIps() { List<String> ips = new ArrayList<>(4); try { Enumeration<NetworkInterface> itfs = NetworkInterface.getNetworkInterfaces(); if (itfs != null) { for (NetworkInterface itf : asIterable(itfs)) { if (!itf.isLoopback()) { Enumeration<InetAddress> addrs = itf.getInetAddresses(); for (InetAddress addr : asIterable(addrs)) { String hostAddr = addr.getHostAddress(); if (!addr.isLoopbackAddress() && !ips.contains(hostAddr)) ips.add(hostAddr); } } } } } catch (SocketException ignore) { return Collections.emptyList(); } Collections.sort(ips); return ips; }
/** * Gets display name of the network interface this IP address belongs to. * * @param addr IP address for which to find network interface name. * @return Network interface name or {@code null} if can't be found. */ @Nullable public static String getNetworkInterfaceName(String addr) { assert addr != null; try { InetAddress inetAddr = InetAddress.getByName(addr); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) for (InetAddress itfAddr : asIterable(itf.getInetAddresses())) if (itfAddr.equals(inetAddr)) return itf.getDisplayName(); } catch (UnknownHostException ignore) { return null; } catch (SocketException ignore) { return null; } return null; }
for (NetworkInterface itf : asIterable(itfs)) { byte[] hwAddr = itf.getHardwareAddress();
List<NetworkInterface> itfs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) itfs.add(itf); boolean found = false; for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLoopbackAddress() && !addr.isLinkLocalAddress() && reachable(itf, addr, reachTimeout)) { locHost = addr;
zip = new ZipFile(zipFile); for (ZipEntry entry : asIterable(zip.entries())) { if (entry.isDirectory()) {
List<InetAddress> locAddrs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) { for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLinkLocalAddress()) locAddrs.add(addr);