weixin_42437164
小夏同学____
2019-04-10 12:57

JAVA中InetAddress.getByName("ip").getHostName();获取的主机名为什么多了后缀.lan?

  • intellij-idea

运行结果如下,本地主机名是XXl,但获取的是XXL.lan;获取的ip地址无误
图片说明

这是代码:

package Pers.Pluto.Day26;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress address = null;  //主机名或者ip地址

        // address = InetAddress.getByName("XXL");
        // address = InetAddress.getLocalHost();
        address = InetAddress.getByName("192.168.1.136");

        String name = address.getHostName();        //获取主机名
        String hostAddress = address.getHostAddress();     //获取本地ip

        System.out.println("主机名:" + name + "\r\n" + "ip:" + hostAddress);


    }
}

运行结果如下,本地主机名是XXl,但获取的是XXL.lan
图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答