从IP解析主机名 [英] Resolve host name from IP

查看:138
本文介绍了从IP解析主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在编写一个程序来列出网络上所有计算机的清单.我设法获得了IP,但是现在我需要解析主机名.我的代码可以解析Windows PC和服务器的主机名,但是不能解析非Windows计算机.

这是我的代码:

Hi all.

I''m writing a program to do a listing of all the computers on a network. I managed to get the IP''s but now I need to resolve the host name. My code works to resolve Windows PC''s and server''s host names but it does not work to resolve non Windows machines.

Here is my code:

Dim host As System.Net.IPHostEntry
host = System.Net.Dns.GetHostByAddress("IP address")
MsgBox(host.HostName)



预先感谢



Thanx in advance

推荐答案

您可以使用Dns.GetHostEntry检索此信息.它可以双向工作,这意味着您可以提供IP并获取主机名,或者提供主机名以获取IP.看看下面的链接.

http://msdn.microsoft.com/en-us/library/ms143998.aspx [ ^ ]

祝你好运!
You can use Dns.GetHostEntry to retrieve this information. It works both ways, meaning you can give an IP and get the hostname or supply the hostname to get the IP. Have a look at the link below.

http://msdn.microsoft.com/en-us/library/ms143998.aspx[^]

Good luck!


我尝试使用Dns.GetHostEntry,但是遇到了同样的问题.

我使用Try-Catch并收到以下消息:请求的名称有效,但未找到请求类型的数据"
I have tried using Dns.GetHostEntrybut but I get the same problem.

I use Try-Catch and get this message: "The requested name is valid, but no data of the requested type was found"


对不起,我不知道你的意思是:(
就像我说的那样,我使用Try-Catch并在出现错误时显示错误. msgbox仅显示以下内容:所请求的名称有效,但未找到所请求类型的数据"

根据我的说法,它可以看到主机在网络上,但无法获取主机名.这仅在Linux计算机上是这种情况.
I''m sorry but I don''t know what you mean :(
Like I said I use the Try-Catch and on error show the error. The msgbox only display this: "The requested name is valid, but no data of the requested type was found"

According to me it sees that the host is on the network but it can''t get the host name. This is only the case with Linux machines.


这篇关于从IP解析主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆