public String getAllLocalIPAddress(){
StringBuilder sbIpaddress = new StringBuilder();
try {
Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces();
// 遍历所用的网络接口
while (en.hasMoreElements()) {
NetworkInterface nif = en.nextElement();// 得到每一个网络接口绑定的所有ip
Enumeration<InetAddress> inet = nif.getInetAddresses();
// 遍历每一个接口绑定的所有ip
while (inet.hasMoreElements()) {
InetAddress ip = inet.nextElement();
sbIpaddress.append(ip.getHostAddress());
sbIpaddress.append("\r\n");
}
}
}
catch(SocketException e)
{
sbIpaddress.append(e.toString());
sbIpaddress.append("\r\n");
}
return sbIpaddress.toString();
}