博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java获取本机IP
阅读量:6885 次
发布时间:2019-06-27

本文共 766 字,大约阅读时间需要 2 分钟。

try {    Enumeration
interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); if (iface.isLoopback() || !iface.isUp()) { continue; } Enumeration
addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr instanceof Inet6Address) { continue; } ip = addr.getHostAddress(); } } } catch (SocketException e) { LoggerUtils.error(String.format("获取本机IP异常:%s", e.getStackTrace()), null); ip = "127.0.0.1";}

转载于:https://www.cnblogs.com/chinaifae/p/10239315.html

你可能感兴趣的文章
html worker 执行函数,Web Worker 详细介绍
查看>>
mcp背景中如何html图片,smtp 邮件正文镶入图片 HTML代码等全过程
查看>>
fdisk非交互自动对磁盘分区格式化
查看>>
疯狂ios讲义之美化iOS应用
查看>>
Exchange 2013 前端 MSExchangeFrontEndTransport 2030的解决
查看>>
累并快乐的2014年
查看>>
让WP7下复杂列表选项生动起来
查看>>
在vSphere中为不同服务器配置IPMI功能
查看>>
nagios一键安装脚本
查看>>
MDT 2013 Update 1 Preview 部署 Windows 10之MDT 2013安装配置
查看>>
监控利器Nagios之一:监控本地NFS和外部HTTP、MySQL服务
查看>>
BGP重分布metric详解
查看>>
虚拟机Virtual PC的使用
查看>>
我的友情链接
查看>>
应该知道的自动化测试陷阱1
查看>>
详解linux运维工程师入门级必备技能
查看>>
第三章 MySQL数据库系统
查看>>
使用阿里云Elasticsearch搭建ELK日志系统
查看>>
爬虫爬取“吟”的技术博客
查看>>
运维监控利器Nagios:概念、结构和功能
查看>>