怎样获取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;
}
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;
}
相关文章推荐
- java网络编程怎样获取ip地址
- 怎样获取访问者真实IP地址
- 怎样用Java来获取真实的IP地址
- SpringMVC怎样获取客户端的ip地址
- 怎样用Java来获取真实的IP地址
- 怎样用Java来获取真实的IP地址
- iOS怎样获取手机的ip地址
- 怎样释放获取到的ip地址及重新获取
- 怎样获取本机的真实IP地址
- 怎样解决Win XP操作系统DHCP故障:获取未使用的IP地址
- android手机充当服务器端时,怎样获取本机的IP地址?
- 在.NET(C#)中获取电脑名IP地址及当前用户名
- 获取远程客户端的真实IP地址
- Android如何获取指定url的ip地址
- C/C++获取IP地址
- java 获取IP地址(要是安装了虚拟机之类的软件可能不准确)
- Yii获取ip地址
- CentOS配置网卡开机自动获取IP地址
- 获取手机IP地址的方法(android)
- javascript获取客户端网卡MAC地址和IP地址和计算机名