我的hosts文件(C:\WINDOWS\system32\drivers\etc\hosts)中有许多IP地址到主机名的映射:
# Switches
192.168.200.254 sw-con-ctrl
192.168.201.253 sw-con-ctrl-2
192.168.201.254 sw-con-ctrl-1
# 192.168.188.1 sw-con-ctrl-ylw-1
# 192.168.189.1 sw-con-ctrl-blu
192.168.190.62 access-console
# Routers
192.168.21.1 rtr1
192.168.22.1 rtr2
我正在尝试通过Java API以编程方式将IPAddress转换为HostName。
伪代码:
IPAddress ip = new IPAddress("192.168.190.62");
String host = ip.getHost();
System.out.println(host); //prints "access-console"