|
@@ -77,12 +77,36 @@ public class DNS {
|
|
|
return attribute.get("PTR").get().toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return NetworkInterface for the given subinterface name (eg eth0:0)
|
|
|
+ * or null if no interface with the given name can be found
|
|
|
+ */
|
|
|
+ private static NetworkInterface getSubinterface(String strInterface)
|
|
|
+ throws SocketException {
|
|
|
+ Enumeration<NetworkInterface> nifs =
|
|
|
+ NetworkInterface.getNetworkInterfaces();
|
|
|
+
|
|
|
+ while (nifs.hasMoreElements()) {
|
|
|
+ Enumeration<NetworkInterface> subNifs =
|
|
|
+ nifs.nextElement().getSubInterfaces();
|
|
|
+
|
|
|
+ while (subNifs.hasMoreElements()) {
|
|
|
+ NetworkInterface nif = subNifs.nextElement();
|
|
|
+ if (nif.getName().equals(strInterface)) {
|
|
|
+ return nif;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns all the IPs associated with the provided interface, if any, in
|
|
|
* textual form.
|
|
|
*
|
|
|
* @param strInterface
|
|
|
- * The name of the network interface to query (e.g. eth0)
|
|
|
+ * The name of the network interface or subinterface to query
|
|
|
+ * (eg eth0 or eth0:0) or the string "default"
|
|
|
* @return A string vector of all the IPs associated with the provided
|
|
|
* interface
|
|
|
* @throws UnknownHostException
|
|
@@ -97,16 +121,14 @@ public class DNS {
|
|
|
InetAddress.getLocalHost().getHostAddress()
|
|
|
};
|
|
|
}
|
|
|
+ NetworkInterface netIf;
|
|
|
try {
|
|
|
- NetworkInterface netIF = NetworkInterface.getByName(strInterface);
|
|
|
- if (netIF == null) {
|
|
|
- throw new UnknownHostException("Unknown interface " + strInterface);
|
|
|
- } else {
|
|
|
- Vector<String> ips = new Vector<String>();
|
|
|
- Enumeration<InetAddress> e = netIF.getInetAddresses();
|
|
|
- while (e.hasMoreElements())
|
|
|
- ips.add(e.nextElement().getHostAddress());
|
|
|
- return ips.toArray(new String[] {});
|
|
|
+ netIf = NetworkInterface.getByName(strInterface);
|
|
|
+ if (netIf == null) {
|
|
|
+ netIf = getSubinterface(strInterface);
|
|
|
+ if (netIf == null) {
|
|
|
+ throw new UnknownHostException("Unknown interface " + strInterface);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (SocketException e) {
|
|
|
LOG.warn("Unable to get IP for interface " + strInterface, e);
|
|
@@ -114,6 +136,11 @@ public class DNS {
|
|
|
InetAddress.getLocalHost().getHostAddress()
|
|
|
};
|
|
|
}
|
|
|
+ Vector<String> ips = new Vector<String>();
|
|
|
+ Enumeration<InetAddress> e = netIf.getInetAddresses();
|
|
|
+ while (e.hasMoreElements())
|
|
|
+ ips.add(e.nextElement().getHostAddress());
|
|
|
+ return ips.toArray(new String[] {});
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -121,7 +148,8 @@ public class DNS {
|
|
|
* network interface
|
|
|
*
|
|
|
* @param strInterface
|
|
|
- * The name of the network interface to query (e.g. eth0)
|
|
|
+ * 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
|
|
|
* @throws UnknownHostException
|
|
|
* If one is encountered in querying the default interface
|
|
@@ -137,7 +165,8 @@ public class DNS {
|
|
|
* address bound to the specified network interface
|
|
|
*
|
|
|
* @param strInterface
|
|
|
- * The name of the network interface to query (e.g. eth0)
|
|
|
+ * The name of the network interface or subinterface to query
|
|
|
+ * (e.g. eth0 or eth0:0) or the string "default"
|
|
|
* @param nameserver
|
|
|
* The DNS host name
|
|
|
* @return A string vector of all host names associated with the IPs tied to
|