规范主机名
谁能告诉我规范主机名的正确概念以及如何检查 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看列出的示例 此处 用于获取 google 的 CanonicalHostName()。
www.google.com 获得的输出之一是
当我在本地机器上运行相同的程序时,我得到的输出为
因此,根据相应 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
When i ran the same program on my local box i got the output as
So , depending how the reppective DNS is configured , variable REQUESTSERVER will have different values accross a network
是的,当然在虚拟主机的(常见)情况下,单个物理主机提供不同的虚拟网站。在这种情况下,客户端访问服务器所使用的主机名可通过 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.