private static String getIpAddress( ){ String ip = "";
Collection<InetAddress> colInetAddress =getAllHostAddress(); for (InetAddress address : colInetAddress) {
if (!address.isLoopbackAddress() && address.getHostAddress().contains(":") != true)
ip = ip + address.getHostAddress() + ",";
} return ip;
} public static Collection<InetAddress> getAllHostAddress() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
Collection<InetAddress> addresses = new ArrayList<InetAddress>(); while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
addresses.add(inetAddress);
}
} return addresses;
} catch (SocketException e) {
throw new RuntimeException(e.getMessage(), e);
}
}