天天看点

Java 获取指定主机IP

import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIP {
    public static void main(String[] args) {
        InetAddress address = null;
        try {
            address = InetAddress.getByName("www.baidu.com");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        System.out.println(address.getHostName()+":"+address.getHostAddress());
        System.exit(0);
    }
}
           
Java 获取指定主机IP