开发者

Canonical Hostname

Can anyone please tell me the proper concept of a canonical hostname and how can I check what is the canonical开发者_Go百科 hostname on Windows?

Actually, I am facing a problem: I have a Java code which converts an input "server name" to its canonical hostname:

try {
    InetAddress in = InetAddress.getByName(REQUESTSERVER);
    REQUESTSERVER = in.getCanonicalHostName();
    System.out.println("Canonical REQUESTSERVER "+ REQUESTSERVER );
} catch(Exception e) {
    System.out.println("lookup failed");
}

Can the variable REQUESTSERVER have different values across a network?


Have a look at the example listed here for getting the CanonicalHostName() for google. One of the output it gets for www.google.com is

Which Host:www.google.com
Canonical Host Name:po-in-f104.google.com
Host Name:www.google.com
Host Address:72.14.253.104

When i ran the same program on my local box i got the output as

Which Host:www.google.com
Canonical Host Name:74.125.227.49
Host Name:www.google.com
Host Address:74.125.227.49

So , depending how the reppective DNS is configured , variable REQUESTSERVER will have different values accross a network


Yes, certainly in the (common) case of virtual hosting where a single physical host provides different virtual websites. In this case the hostname used by the client to access the server will be available from the Java Servlet method ServletRequest.getServerName().

See this SO question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜