java实现根据域名获得ip地址代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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

public class GetIPAddressFromHostname {

    public static void main(String[] args) {

        try {

            InetAddress inetAddr = InetAddress.getByName("open-open.com");

            byte[] addr = inetAddr.getAddress();

            // Convert to dot representation
            String ipAddr = "";
            for (int i = 0; i < addr.length; i++) {
                if (i > 0) {
                    ipAddr += ".";
                }
                ipAddr += addr[i] & 0xFF;
            }

            System.out.println("IP Address: " + ipAddr);

        }
        catch (UnknownHostException e) {
            System.out.println("Host not found: " + e.getMessage());
        }

    }

}