import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
public class GetIp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Enumeration<NetworkInterface> netInterfaces = null;
try {
netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = netInterfaces.nextElement();
Enumeration<InetAddress> ips = ni.getInetAddresses();
if (ni.getName().equals("cloudbr0")) {
ips.nextElement().getHostAddress();
System.out.println("###IP=" + ips.nextElement().getHostAddress());
}
}
} catch (Exception e) {
System.out.println("###error");
e.printStackTrace();
}
}
}
import java.net.NetworkInterface;
import java.util.Enumeration;
public class GetIp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Enumeration<NetworkInterface> netInterfaces = null;
try {
netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = netInterfaces.nextElement();
Enumeration<InetAddress> ips = ni.getInetAddresses();
if (ni.getName().equals("cloudbr0")) {
ips.nextElement().getHostAddress();
System.out.println("###IP=" + ips.nextElement().getHostAddress());
}
}
} catch (Exception e) {
System.out.println("###error");
e.printStackTrace();
}
}
}