/** * Like {@link DNS#getIPs(String, boolean), but returns all * IPs associated with the given interface and its subinterfaces. */ public static String[] getIPs(String strInterface) throws UnknownHostException { return getIPs(strInterface, true); }
/** * Returns the first available IP address associated with the provided * network interface or the local host IP if "default" is given. * * @param strInterface * The name of the network interface or subinterface to query * (e.g. eth0 or eth0:0) or the string "default" * @return The IP address in text form, the local host IP is returned * if the interface name "default" is specified * @throws UnknownHostException * If the given interface is invalid */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Like {@link DNS#getIPs(String, boolean), but returns all * IPs associated with the given interface and its subinterfaces. */ public static String[] getIPs(String strInterface) throws UnknownHostException { return getIPs(strInterface, true); }
/** * Like {@link DNS#getIPs(String, boolean), but returns all * IPs associated with the given interface and its subinterfaces. */ public static String[] getIPs(String strInterface) throws UnknownHostException { return getIPs(strInterface, true); }
/** * Like {@link DNS#getIPs(String, boolean), but returns all * IPs associated with the given interface and its subinterfaces. */ public static String[] getIPs(String strInterface) throws UnknownHostException { return getIPs(strInterface, true); }
/** * Like {@link DNS#getIPs(String, boolean), but returns all * IPs associated with the given interface and its subinterfaces. */ public static String[] getIPs(String strInterface) throws UnknownHostException { return getIPs(strInterface, true); }
/** * Returns the first available IP address associated with the provided * network interface or the local host IP if "default" is given. * * @param strInterface * The name of the network interface or subinterface to query * (e.g. eth0 or eth0:0) or the string "default" * @return The IP address in text form, the local host IP is returned * if the interface name "default" is specified * @throws UnknownHostException * If the given interface is invalid */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns the first available IP address associated with the provided * network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @return The IP address in text form * @throws UnknownHostException * If one is encountered in querying the default interface */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns the first available IP address associated with the provided * network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @return The IP address in text form * @throws UnknownHostException * If one is encountered in querying the default interface */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns the first available IP address associated with the provided * network interface or the local host IP if "default" is given. * * @param strInterface * The name of the network interface or subinterface to query * (e.g. eth0 or eth0:0) or the string "default" * @return The IP address in text form, the local host IP is returned * if the interface name "default" is specified * @throws UnknownHostException * If the given interface is invalid */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns the first available IP address associated with the provided * network interface or the local host IP if "default" is given. * * @param strInterface * The name of the network interface or subinterface to query * (e.g. eth0 or eth0:0) or the string "default" * @return The IP address in text form, the local host IP is returned * if the interface name "default" is specified * @throws UnknownHostException * If the given interface is invalid */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns the first available IP address associated with the provided * network interface or the local host IP if "default" is given. * * @param strInterface * The name of the network interface or subinterface to query * (e.g. eth0 or eth0:0) or the string "default" * @return The IP address in text form, the local host IP is returned * if the interface name "default" is specified * @throws UnknownHostException * If the given interface is invalid */ public static String getDefaultIP(String strInterface) throws UnknownHostException { String[] ips = getIPs(strInterface); return ips[0]; }
/** * Returns all the host names associated by the provided nameserver with the * address bound to the specified network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @param nameserver * The DNS host name * @return A string vector of all host names associated with the IPs tied to * the specified interface * @throws UnknownHostException */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (Exception e) { } if (hosts.size() == 0) return new String[] { InetAddress.getLocalHost().getCanonicalHostName() }; else return hosts.toArray(new String[] {}); }
/** * Returns all the host names associated by the provided nameserver with the * address bound to the specified network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @param nameserver * The DNS host name * @return A string vector of all host names associated with the IPs tied to * the specified interface * @throws UnknownHostException */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (Exception e) { } if (hosts.size() == 0) return new String[] { InetAddress.getLocalHost().getCanonicalHostName() }; else return hosts.toArray(new String[] {}); }
String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) {
/** * Get the IP addresses of an unknown interface, expect to get something * back * @throws Exception if something went wrong */ public void testIPsOfUnknownInterface() throws Exception { String[] ips = DNS.getIPs("name-of-an-unknown-interface"); assertNotNull(ips); assertTrue(ips.length > 0); }
/** * Get the IP addresses of an unknown interface */ @Test public void testIPsOfUnknownInterface() throws Exception { try { DNS.getIPs("name-of-an-unknown-interface"); fail("Got an IP for a bogus interface"); } catch (UnknownHostException e) { assertEquals("No such interface name-of-an-unknown-interface", e.getMessage()); } }
/** * Get the IP addresses of an unknown interface */ @Test public void testIPsOfUnknownInterface() throws Exception { try { DNS.getIPs("name-of-an-unknown-interface"); fail("Got an IP for a bogus interface"); } catch (UnknownHostException e) { assertEquals("No such interface name-of-an-unknown-interface", e.getMessage()); } }
/** * Test the "default" IP addresses is the local IP addr */ @Test public void testGetIPWithDefault() throws Exception { String[] ips = DNS.getIPs(DEFAULT); assertEquals("Should only return 1 default IP", 1, ips.length); assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString()); String ip = DNS.getDefaultIP(DEFAULT); assertEquals(ip, ips[0].toString()); }
/** * Test the "default" IP addresses is the local IP addr */ @Test public void testGetIPWithDefault() throws Exception { String[] ips = DNS.getIPs(DEFAULT); assertEquals("Should only return 1 default IP", 1, ips.length); assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString()); String ip = DNS.getDefaultIP(DEFAULT); assertEquals(ip, ips[0].toString()); }