// 获取本地ip地址
public static String getServerIP() {
InetAddress[] inetAdds;
String serverIP = null;
try {
inetAdds = InetAddress.getAllByName(InetAddress.getLocalHost()
.getHostName());
for (int i = 0; i < inetAdds.length; i++) {
serverIP = inetAdds[i].getHostAddress();
if (!"127.0.0.1".equals(serverIP) && serverIP.length() <= 15
&& !serverIP.contains(":")) {
System.out.println(serverIP);
}
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
return serverIP;
}