getlocalhost专题

使用NetworkInterface解决InetAddress.getLocalHost().getHostAddress()获取ip为127.0.0.1问题

InetAddress.getLocalHost().getHostAddress() 根据本机名去/etc/hosts中获取对应ip,所以经常会出现获取到127.0.0.1的情况,使用NetworkInterface.getNetworkInterfaces()从网卡中获取ip可避免该情况。工具类如下 import java.net.Inet4Address;import j