如何在 Java 中检查系统 IP 地址/主机名?
有没有办法在不使用外部进程的情况下找出系统IP地址? 我想为我的应用程序获取这些信息,但如果可能的话,使用纯java。
is there any way to find out system IP Address without using external process?
I want to grab this information for my application but in pure java if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这满足您的需求吗?
Does this meet your needs?
InetAddress.getLocalHost().getHostAddress() 调用并不总是有效;有时它会返回 127.0.0.1。
请参阅 java InetAddress.getLocalHost( );返回 127.0.0.1 ...如何获取真实 IP? 了解更多详细信息和其他选项。
The InetAddress.getLocalHost().getHostAddress() call doesn't always work; sometimes it returns 127.0.0.1.
See java InetAddress.getLocalHost(); returns 127.0.0.1 ... how to get REAL IP? for some more details and other options.
查看 InetAddress http://download。 oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html
Have a look at InetAddress http://download.oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html
您好,是的,通过 InetAdres 类可以实现。检查此链接 JAVA API 和您需要的方法是 getHostAddress()
Hi yes its possible with the class InetAddres. Check this link JAVA API and the method you need is getHostAddress()
考虑使用 NetworkInterface 类。
Consider using the NetworkInterface class.
如果你想在java应用程序中查找ip地址
并且如果你正在使用web应用程序
If you want to find ip address in java application
and if you are using web application