java 获得本地ip_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java 获得本地ip

java 获得本地ip

 2013/11/28 18:34:03  rain_2372  程序员俱乐部  我要评论(0)
  • 摘要:EnumerationallNetInterfaces=NetworkInterface.getNetworkInterfaces();InetAddressip=null;while(allNetInterfaces.hasMoreElements()){NetworkInterfacenetInterface=(NetworkInterface)allNetInterfaces.nextElement();System.out.println(netInterface.getName())
  • 标签:Java
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements())
{
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
System.out.println(netInterface.getName());
Enumeration addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements())
{
ip = (InetAddress) addresses.nextElement();
if (ip != null && ip instanceof Inet4Address)
{
System.out.println("本机的IP = " + ip.getHostAddress());
}
}
}


发表评论
用户名: 匿名