您的位置:首页 > 其它

怎样获取IP地址

2011-09-05 09:50 169 查看
public String getLocalIpAddress(){

try {

for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();en.hasMoreElements();){

NetworkInterface intf = en.nextElement();

for(Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();enumIpAddr.hasMoreElements();){

InetAddress inetAddress = enumIpAddr.nextElement();

if(!inetAddress.isLoopbackAddress()){

return inetAddress.getHostAddress().toString();

}

}

}

} catch (SocketException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: