windows 将主机名解析为 IP 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3184615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:25:45  来源:igfitidea点击:

Resolve host name to an ip address

windowsnetworkingip-address

提问by Mahesh

I developed a client/server simulation application. I deployed client and server on two different Windows XP machines. Somehow, the client is not able to send requests to the server.

我开发了一个客户端/服务器模拟应用程序。我在两台不同的 Windows XP 机器上部署了客户端和服务器。不知何故,客户端无法向服务器发送请求。

I tried below options:

我尝试了以下选项:

  1. Pinged server machine successfully from client using ip-address.

  2. Pinged client machine successfully from server using ip-address.

  3. Checked netstat command line tool from both machines. Server is in LISTENINGmode and client is in SYS_SENTmode. But the foreign address it is using to send is host name not the ip address.

  4. Pinged server machine unsuccessfully using host name from client.

  5. Pinged client machine successfully using host name from server.

  1. 使用 ip-address 从客户端成功 Ping 服务器机器。

  2. 使用 ip-address 从服务器成功 ping 客户端机器。

  3. 从两台机器检查 netstat 命令行工具。服务器处于LISTENING模式,客户端处于SYS_SENT模式。但是它用来发送的外部地址是主机名而不是 IP 地址。

  4. 使用来自客户端的主机名 ping 服务器计算机失败。

  5. 使用来自服务器的主机名成功 Ping 客户端计算机。

I feel the problem is when the client is trying to connect to the server using the host name.

我觉得问题出在客户端尝试使用主机名连接到服务器时。

Could you please let me know how to force an application to use an ip address instead of a host name? Is there any other way to map the host name to an ip address?

您能否让我知道如何强制应用程序使用 IP 地址而不是主机名?有没有其他方法可以将主机名映射到 IP 地址?

回答by paxdiablo

Go to your client machine and type in:

转到您的客户端机器并输入:

nslookup server.company.com

substituting the real host name of your server for server.company.com, of course.

server.company.com当然,用服务器的真实主机名代替。

That should tell you which DNS server your client is using (if any) and what it thinks the problem is with the name.

这应该会告诉您您的客户端正在使用哪个 DNS 服务器(如果有)以及它认为名称有什么问题。

To forcean application to use an IP address, generally you just configure it to use the IP address instead of a host name. If the host name is hard-coded, or the application insists on using a host name in preference to an IP address (as one of your other comments seems to indicate), then you're probably out of luck there.

强制应用程序使用 IP 地址,通常只需将其配置为使用 IP 地址而不是主机名。如果主机名是硬编码的,或者应用程序坚持优先使用主机名而不是 IP 地址(正如您的其他评论之一似乎表明的那样),那么您可能不走运。

However, you can change the way that most machine resolve the host names, such as with /etc/resolv.confand /etc/hostson UNIXy systems and a local hosts fileon Windows-y systems.

但是,你可以改变的方式,大部分机解析主机名,如用/etc/resolv.conf/etc/hosts上UNIXy系统和本地hosts文件在Windows-Y系统。

回答by IT wannabe

Try tracert to resolve the hostname. IE you have Ip address 8.8.8.8 so you would use; tracert 8.8.8.8

尝试 tracert 解析主机名。IE 你有 Ip 地址 8.8.8.8 所以你会使用;跟踪器 8.8.8.8

回答by Sathya

You could use a C function getaddrinfo() to get the numerical address - both ipv4 and ipv6. See the example code here

您可以使用 C 函数 getaddrinfo() 来获取数字地址 - ipv4 和 ipv6。请参阅此处的示例代码

回答by Richard Chambers

Windows XP has the Windows Firewall which can interfere with network traffic if not configured properly. You can turn off the Windows Firewall, if you have administrator privileges, by accessing the Windows Firewall applet through the Control Panel. If your application works with the Windows Firewall turned off then the problem is probably due to the settings of the firewall.

Windows XP 具有 Windows 防火墙,如果配置不当,它会干扰网络流量。如果您具有管理员权限,您可以通过控制面板访问 Windows 防火墙小程序来关闭 Windows 防火墙。如果您的应用程序在关闭 Windows 防火墙的情况下工作,那么问题可能是由于防火墙的设置。

We have an application which runs on multiple PCs communicating using UDP/IP and we have been doing experiments so that the application can run on a PC with a user who does not have administrator privileges. In order for our application to communicate between multiple PCs we have had to use an administrator account to modify the Windows Firewall settings.

我们有一个应用程序在多台 PC 上运行,使用 UDP/IP 进行通信,我们一直在做实验,以便应用程序可以在没有管理员权限的用户的 PC 上运行。为了让我们的应用程序在多台 PC 之间进行通信,我们必须使用管理员帐户来修改 Windows 防火墙设置。

In our application, one PC is designated as the server and the others are clients in a server/client group and there may be several groups on the same subnet.

在我们的应用程序中,一台 PC 被指定为服务器,其他 PC 是服务器/客户端组中的客户端,并且同一子网上可能有多个组。

The first change was to use the functionality of the Exceptions tab of the Windows Firewall applet to create an exception for the port that we use for communication.

第一个更改是使用 Windows 防火墙小程序的“例外”选项卡的功能为我们用于通信的端口创建例外。

We are using host name lookup so that the clients can locate their assigned server by using the computer name which is composed of a mnemonic prefix with a dash followed by an assigned terminal number (for instance SERVER100-1). This allows several servers with their assigned clients to coexist on the same subnet. The client uses its prefix to generate the computer name for the assigned server and to then use host name lookup to discover the IP address of the assigned server.

我们正在使用主机名查找,以便客户端可以通过使用由助记前缀和破折号后跟指定终端号(例如 SERVER100-1)组成的计算机名称来定位他们指定的服务器。这允许多个服务器及其分配的客户端共存于同一子网上。客户端使用其前缀为分配的服务器生成计算机名称,然后使用主机名查找来发现分配的服务器的 IP 地址。

What we found is that the host name lookup using the computer name (assigned through the Computer Name tab of the System Properties dialog) would not work unless the server PC's Windows Firewall had the File and Printer Sharing Service port enabled.

我们发现,除非服务器 PC 的 Windows 防火墙启用了文件和打印机共享服务端口,否则使用计算机名称(通过“系统属性”对话框的“计算机名称”选项卡分配)的主机名查找将不起作用。

So we had to make two changes: (1) setup an exception for the port we used for communication and (2) enable File and Printer Service in the Exceptions tab to allow for the host name lookup.

因此,我们必须进行两项更改:(1) 为我们用于通信的端口设置一个例外,以及 (2) 在“例外”选项卡中启用“文件和打印机服务”以允许查找主机名。

** EDIT **

** 编辑 **

You may also find this Microsoft Knowledge Base article on helpful on Windows XP networking.

您可能还会发现这篇关于 Windows XP 网络的 Microsoft 知识库文章很有帮助

And see this article on NETBIOS name resolution in Windows.

并参阅有关 Windows 中的 NETBIOS 名称解析的这篇文章

回答by unwind

This is hard to answer without more detail about the network architecture. Some things to investigate are:

如果没有关于网络架构的更多细节,这很难回答。需要调查的一些事情是:

  • Is it possible that client and/or server is behind a NAT device, a firewall, or similar?
  • Is any of the IP addresses involved a "local" address, like 192.168.x.y or 10.x.y.z?
  • What are the host names, are they "real" DNS:able names or something more local and/or Windows-specific?
  • How does the client look up the server? There must be a place in code or config data that holds the host name, simply try using the IP there instead if you want to avoid the lookup.
  • 客户端和/或服务器是否可能位于 NAT 设备、防火墙或类似设备之后?
  • 是否有任何 IP 地址涉及“本地”地址,例如 192.168.xy 或 10.xyz?
  • 什么是主机名,它们是“真正的”DNS:可用名称还是更本地和/或特定于 Windows 的名称?
  • 客户端如何查找服务器?代码或配置数据中必须有一个地方保存主机名,如果您想避免查找,只需尝试在那里使用 IP。