开发者

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

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 w开发者_C百科ay that doesn't involve DNS and/or knowledge of the host name.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜