How can I find all locally bound IP addresses in Java?

倖福魔咒の 提交于 2019-12-11 01:22:03

问题


I would like to have all locally bound IP addresses, basically an array of java.net.InetAddress. I know I can call InetAddress.getAllByName() with the host name, but I was wondering if there is a more direct way that doesn't involve DNS and/or knowledge of the host name.


回答1:


java.net.NetworkInterface.getNetworkInterfaces() will give you an enumeration of the available network interfaces. You can then invoke getInetAddresses() on each NetworkInterface to get the addresses bound to this interface.



来源:https://stackoverflow.com/questions/1827270/how-can-i-find-all-locally-bound-ip-addresses-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!