类似nslookup

摘自:http://www.javadb.com/perform-nslookup-with-the-inetaddress-class
import java.net.InetAddress;
import java.net.UnknownHostException;

/*
 * Main.java
 *
 * @author www.javadb.com
 */
public class Main {
    
    /*
     * This method performs a NS Lookup
     */
    public void performNSLookup() {
        
        try {
            
            InetAddress inetHost = InetAddress.getByName("cnn.com");
            String hostName = inetHost.getHostName();
            System.out.println("The host name was: " + hostName);
            System.out.println("The hosts IP address is: " + inetHost.getHostAddress());
            
        } catch(UnknownHostException ex) {
            
            System.out.println("Unrecognized host");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().performNSLookup();
    }
}

版权声明:本文为miraclespace原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/miraclespace/archive/2011/09/19/3712390.html