monojeet
monojeet

Reputation: 11

Canonical Hostname

Can anyone please tell me the proper concept of a canonical hostname and how can I check what is the canonical 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?

Upvotes: 1

Views: 4190

Answers (2)

Clyde Lobo
Clyde Lobo

Reputation: 9174

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

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122391

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.

Upvotes: 0

Related Questions