NetworkInterface getSubInterfaces Example
NetworkInterface class getSubInterfaces example. This example shows you how to use getSubInterfaces method.
NetworkInterface class getSubInterfaces example.public Enumeration getSubInterfaces() Get an Enumeration with all the subinterfaces (also known as virtual interfaces) attached to this network interface. For instance eth0:1 will be a subinterface to eth0.
Here is the code
/*
* @ # GetParent.java
* A class repersenting use to getParent method
* of URL class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
import java.util.*;
public class GetSubInterfaces {
public static void main(String[] args) throws Exception {
byte b[] = {127, 0, 0, 1};
InetAddress inetAddress = InetAddress.getByAddress(b);
NetworkInterface networkInterface =
NetworkInterface.getByInetAddress(inetAddress);
Enumeration<NetworkInterface> e = networkInterface.getSubInterfaces();
System.out.println("Sub Interfaces : " + e.hasMoreElements());
for (NetworkInterface netinfo : Collections.list(e)) {
System.out.println(netinfo.getDisplayName());
}
}
} |
|