Java getInetAddresses()返回MAC OSX中的原始Ip地址

Java getInetAddresses()返回MAC OSX中的原始Ip地址,java,Java,我正在使用java.net中的NetworkInterface.getInetAddresses()获取本地主机名和ip地址。我在MacOSX中得到异常“主机名是原始IP地址”,因为它在原始IP地址中重新调整。在windows中工作正常(返回DNS主机名)。我是否需要进行任何配置更改以在MAC中获得正确的结果 NetworkInterface netInterface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost())

我正在使用java.net中的NetworkInterface.getInetAddresses()获取本地主机名和ip地址。我在MacOSX中得到异常“主机名是原始IP地址”,因为它在原始IP地址中重新调整。在windows中工作正常(返回DNS主机名)。我是否需要进行任何配置更改以在MAC中获得正确的结果

 NetworkInterface netInterface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
            Enumeration addresses = netInterface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress addr = (InetAddress) addresses.nextElement();
                String hostName = addr.getHostName();
                String ipAddress = addr.getHostAddress();
                // If host name is raw IP address in a string format then throw exception.
                if(hostName.equals(ipAddress)){
                    throw new Exception("Host name is raw IP address; domain="+domain);
                }
//                 If the host name is qualified, determine the raw host name.
                int period = hostName.indexOf('.');
                if (period >= 0) {
                    hostName = hostName.substring(0, period);
                }
                localHosts.add(hostName.toLowerCase(Locale.US));
            }