来自IP地址的HTTPS主机名

时间:2016-02-21 20:34:59

标签: java youtube ip host hostname

我一直在尝试从IP地址获取主机名。只要我提供http请求,它就可以正常工作。但是,当我提供https IP地址时,它会返回相同的IP地址而不是名称。

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

public class IPTest {
    public static void main(String args[]) throws UnknownHostException {  
        InetAddress addr = InetAddress.getLocalHost();
        String ipAddress = addr.getHostAddress();    
        System.out.println("IP address of localhost : " + ipAddress);
        String hostname = addr.getHostName();
        System.out.println("Name of hostname : " + hostname);


        //Youtube IP Address as it's using HTTPS
        InetAddress addr2 = InetAddress.getByName("92.226.0.76");
        String host = addr2.getHostName();
        System.out.println(host);
    }
}

0 个答案:

没有答案