return netList;
}
public static NetInterfaceObject getNetInfoObject(String interfaceName) {
NetInterfaceObject netObj = new NetInterfaceObject();
try {
Enumeration networks = NetworkInterface.getNetworkInterfaces();
for (Object netint : Collections.list(networks)) {
NetworkInterface netInterface = (NetworkInterface) netint;
if (interfaceName.equals(netInterface.getDisplayName())) {
// get the name of the interface
netObj.setName(netInterface.getDisplayName());
netObj.setIsVirtual(netInterface.isVirtual());
try {
// get the MAC address of the interface
netObj.setHardwareAddress(
netInterface.getHardwareAddress());
// test if the interface is up and running
netObj.setIsUp(netInterface.isUp());
netObj.setIsLoopback(netInterface.isLoopback());
} catch (SocketException ex) {
Logger.getLogger(
NetInterface.class.getName()).log(
Level.SEVERE, null, ex);
}
// get the IP addresses of this interface
Vector<String> ipVector = new Vector<String>();
Vector<String> hostNameVector = new Vector<String>();
Enumeration ipAddress = netInterface.getInetAddresses();
for (Object ipAdd : Collections.list(ipAddress)) {
InetAddress ip = (InetAddress) ipAdd;
ipVector.add(ip.getHostAddress());
hostNameVector.add(ip.getCanonicalHostName());
}
if (!ipVector.isEmpty()) {
// add the IP address
netObj.setIpAddress(ipVector.lastElement());
}
if (!hostNameVector.isEmpty()) {
// add the host name
netObj.setHostName(hostNameVector.lastElement());
}
}
}
} catch (SocketException ex) {
Logger.getLogger(NetInterface.class.getName()).log(