转换IP地址通过DNS.GetHostEntry主机名 [英] Converting IP address to host name via DNS.GetHostEntry

查看:529
本文介绍了转换IP地址通过DNS.GetHostEntry主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过传递的ip地址来获得主机名。我用下面的code。

I am trying to get the hostname by passing in the ip address. I use the following code.

System.Net.Dns.GetHostEntry("192.168.x.x").HostName

有关某些主机上面code为正确返回的主机名,但对于其他一些主持人抛出异常'没有找到这样的主机。

For some host the above code is returning correctly the hostname, but for few other host it throws an exception 'No Such host found'.

可以在任何一个可以告诉我为什么会这样对于一些主机?

Could any one tell me why is this happening for some hosts?

我使用上述code在一个asp.net MVC应用程序。

I used the above code in an asp.net mvc application.

推荐答案

并非所有IP的与反向DNS条目设置正确。这些IP的通常是终端消费者对懒惰的ISP谁不为他们的客户提供 PTR 记录。如果没有相反的条目,你可以打赌,没有向前进入任一。因此,这些主机必须在所有主机名没有,因此例外。你需要捕获这个异常,这些主机和用别的东西,如他们的IP作为标识符。

Not all IP's are setup properly with a reverse DNS entry. These IP's are typically end consumers on lazy ISP's who don't provide PTR records for their clients. If there's no reverse entry, you can bet there's no forward entry either. As such, these hosts have no hostname at all, hence the exception. You'll need to catch this exception for these hosts and use something else such as their IP as an identifier.

这篇关于转换IP地址通过DNS.GetHostEntry主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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