IPGetUtil 获取ip地址公用类
来源:互联网 发布:movidius 知乎 编辑:程序博客网 时间:2024/05/16 14:54
public class IPGetUtil { private static final Logger log = Logger.getLogger(IPGetUtil.class); /** * * getLocalIpAddress(获取ip) * * @Title: getLocalIpAddress * @param @return * @return String * @throws */ public static String getLocalIpAddress() { StringBuffer ips = new StringBuffer(); Enumeration<NetworkInterface> allNetInterfaces; // 定义网络接口枚举类 try { allNetInterfaces = NetworkInterface.getNetworkInterfaces(); // 获得网络接口 InetAddress ip = null; // 声明一个InetAddress类型ip地址 while (allNetInterfaces.hasMoreElements()) // 遍历所有的网络接口 { NetworkInterface netInterface = allNetInterfaces.nextElement(); Enumeration<InetAddress> addresses = netInterface .getInetAddresses(); // 同样再定义网络地址枚举类 while (addresses.hasMoreElements()) { ip = addresses.nextElement(); if (ip != null && (ip instanceof Inet4Address) && !"127.0.0.1".equals(ip.getHostAddress() .toString())) // InetAddress类包括Inet4Address和Inet6Address { ips.append(ip.getHostAddress()).append("|"); } } } } catch (Exception e) { log.error("获取本地ip异常:" + e); } return ips.toString().substring(0, ips.toString().length() - 1); } /** * getLocalIp(获取ip) * @Title: getLocalIp * @param @return * @return String * @throws */ public static String getLocalIp() { InetAddress ia=null; String localip=null; try { ia=InetAddress.getLocalHost(); //String localname=ia.getHostName(); localip=ia.getHostAddress(); } catch (Exception e) { log.error("获取本地ip异常getLocalIp():" + e); } return localip; }}
1 0
- IPGetUtil 获取ip地址公用类
- 获取IP工具类IPGetUtil
- VB6获取本机所有IP地址公用函数
- 公用IP地址及私用IP地址
- 公用IP地址和专用IP地址
- 获取IP地址 -- CIPAddressCtrl类
- 获取手机ip地址工具类
- 获取IP地址的一个工具类
- qt获取网络ip地址的类
- IPUtil类---获取登录用户IP地址
- 获取客户端ip地址工具类
- 获取客户端IP地址
- 获取IP地址!
- 获取IP地址
- 获取IP地址
- 获取对方ip地址
- 获取 IP 地址
- 获取客户端ip地址
- Linux 套接字编程中 bind 错误:bind fail:Address already in use 解决方法
- Delphi 通过字符串实例化类
- 不同版本的Spring与Redis集群配置
- 实践证明
- 图片适配自定义控件
- IPGetUtil 获取ip地址公用类
- Android中Thread、Handler、Looper、MessageQueue的原理分析
- windows Heap manager
- linux查看网口和哪些ip地址链接
- Linux内存描述之内存页面page--Linux内存管理(四)
- HTML5之Canvas 2D入门2 - Canvas绘制图形
- 比较精准的答案
- 虚函数对于dynamic_cast转换的作用
- leetcode:数学:Count Numbers with Unique Digits(357)