Java InetAddress class and its common methods
•
Java
Example 1
public static void main(String[] args) { try { InetAddress ia1=InetAddress.getByName("www.qq.com"); System.out.println(ia1.getHostName()); System.out.println(ia1.getHostAddress()); } catch(UnkNownHostException e) { e.printStackTrace(); } }
try { InetAddress ia2=InetAddress.getByName("61.135.169.105"); System.out.println(ia2.getHostName()); System.out.println(ia2.getHostAddress()); } catch(UnkNownHostException e) { e.printStackTrace(); }
try { InetAddress ia3=InetAddress.getLocalHost(); System.out.println("主机名:"+ia3.getHostName()); System.out.println("本地ip地址:"+ia3.getHostAddress()); } catch(UnkNownHostException e) { e.printStackTrace(); }
www.qq.com 123.151.137.18 61.135.169.105 61.135.169.105 主机名:WQ-20161107KCPN 本地ip地址:192.168.0.102
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码