/**
* get local ip
*
* @return
*/
private static String localIP() {
Enumeration<NetworkInterface> netInterfaces = null;
try {
netInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
e.printStackTrace();
}
String localip = "";
InetAddress ip = null;
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = netInterfaces.nextElement();
List<InterfaceAddress> list = ni.getInterfaceAddresses();
for (int i = 0; i < list.size(); i++) {
ip = list.get(i).getAddress();
if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {
localip += ip.getHostAddress().toString();
return localip;
}
}
}
return localip;
}