2019独角兽企业重金招聘Python工程师标准>>>
public static void main(String[] args) throws UnknownHostException {
InetAddress hh = InetAddress.getByName("my.oschina.net");
String domainName = hh.getHostName();
String ipName = hh.getHostAddress();
System.out.println(domainName);
System.out.println(ipName);
System.out.println(hh);
System.out.println("===========================\n\n");
InetAddress ip = InetAddress.getByName("220.170.91.169");
String domainName1 = ip.getHostName();
String ipName1 = ip.getHostAddress();
System.out.println(domainName1);
System.out.println(ipName1);
System.out.println(ip);
System.out.println("===========================\n\n");
InetAddress address = InetAddress.getLocalHost();
String hostName = address.getHostName();
System.out.println(hostName);
}
运行结果:
my.oschina.net
220.170.91.169
my.oschina.net/220.170.91.169
===========================
220.170.91.169
220.170.91.169
220.170.91.169/220.170.91.169
===========================
guanguan.local
Process finished with exit code 0