How to get the ip of the computer on linux through Java?

前端 未结 5 1336
忘掉有多难
忘掉有多难 2020-12-05 15:56

How to get the ip of the computer on linux through Java ?

I searched the net for examples, I found something regarding NetworkInterface class, but I can\'t wrap my

5条回答
  •  囚心锁ツ
    2020-12-05 16:22

    The simplest solution in my case was Socket.getLocalAddress(). I had to open the Socket specifically for that purpose, but with all the NetworkInterfaces on my Ubuntu 10.04 machine it was the only way to get the external IP address.

提交回复
热议问题