规范主机名

发布于 2024-10-12 16:09:21 字数 415 浏览 0 评论 0原文

谁能告诉我规范主机名的正确概念以及如何检查 Windows 上的规范主机名是什么?

实际上,我面临一个问题:我有一个 Java 代码,它将输入的“服务器名称”转换为其规范主机名:

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

变量 REQUESTSERVER 在网络上可以有不同的值吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琴流音 2024-10-19 16:09:21

查看列出的示例 此处 用于获取 google 的 CanonicalHostName()。
www.google.com 获得的输出之一是

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

当我在本地机器上运行相同的程序时,我得到的输出为

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

因此,根据相应 DNS 的配置方式,变量 REQUESTSERVER 在整个网络中将具有不同的值

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

揽清风入怀 2024-10-19 16:09:21

是的,当然在虚拟主机的(常见)情况下,单个物理主机提供不同的虚拟网站。在这种情况下,客户端访问服务器所使用的主机名可通过 Java Servlet 方法 ServletRequest.getServerName() 获得。

请参阅此SO问题

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文