java - InetAddress.getLocalHost().getHostAddress()的返回值问题?
PHPz
PHPz 2017-04-17 17:50:38
0
1
472
import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; public class Demo { public static void main(String[] args) { InetAddress address = null; try { address = InetAddress.getLocalHost(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } /** * 169.254.86.58 */ System.out.println(address.getHostAddress()); } }

上面的代码输出169.254.86.58 ,而我机器的IP地址是59开头的。
我的笔记本使用网线连上的网络, 然后开启了WiFi共享的功能,然后运行上面的代码结果输出的是169.254.86.58,如果我关闭了WiFi共享功能, 那么上面的代码就能够输出59开头的IP地址。
这是为什么呢?

PHPz
PHPz

学习是最好的投资!

reply all (1)
小葫芦
  • Addresses in the range 169.254.xxx.xxx are link local IP addresses. These are reserved for use on a single network segment.
    After turning on the WiFi sharing function, a new LAN will be opened

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!