root :/home/James/mypro/Network/Host-IP# java network.other.HostnameToIP www.baidu.com
www.baidu.com/61.135.169.105
www.baidu.com/61.135.169.125
root :/home/James/mypro/Network/Host-IP# java network.other.HostnameToIP baidu.com
baidu.com/220.181.111.86
baidu.com/123.125.114.144
baidu.com/220.181.111.85
package network.other;import java.net.*;public class HostnameToIP { public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: java network.other.HostnametoIP [hostname]"); } String hostname = args[0]; try { InetAddress[] address = InetAddress.getAllByName(hostname); for (int i=0; i
对比C语言实现,Java的封装确实方便。