如何从IP地址转换为主机名 [英] How to convert from IP address to Host Name

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

问题描述

我有一个程序可以生成一个类似于ip的列表,通过网卡修改





  31  13  64  1  
31 13 64 1
23 65 181 34
23 65 181 34
173 194 113 69
31 . 13 64 1
69 171 235 16
173 252 110 27
173 194 70 125
195 27 155 40
77 67 96 240
31 13 86 16
192 168 1 1
65 39 . 148 3





如何将每个IP转换为它的主机名?







我尝试了下面的代码



  String  ip =   31.13.86.16; 
String host_name = System.Net.Dns.GetHostEntry(ip).HostName;
file.WriteLine(host_name);





并保持例外





我会根据你的意思实现

当我传递一个没有主机名的IP地址时

返回GetHostEntry(ip);将是NULL或没有什么

或者我不知道

因此它出了问题

现在怎么样Handel这个?



plz help

解决方案

你描述的大多数地址都是互联网地址,所以它们没有主机名在您的代码似乎认为他们这样做的意义上。您尝试做的事情称为反向DNS,但这些只能在局域网内工作,其中DHCP服务器(通常是您的路由器)已将IP地址分配给它直接联系的各种连接设备。



说到互联网,事情并不是那么明确,而且主机名不适用,因为你不能使用它 - 你无法通过它的主机名访问计算机IP地址通过他们的路由器。部分原因是出于安全原因:您是否希望网站直接通过您的计算机进行搜索?



相反,使用IP地址,这是您可能正在寻找的域名。如果是您的第一个地址,您可能正在尝试找到域名facebook.com。同样存在的问题是,单个IP地址可能托管多个域,因此没有一个主机名可以返回。



没有集中查找IP到域翻译的服务 - 如果你想这样做,你将需要访问IP并查看它返回的网站...

有像whois.com这样的服务可以分辨您拥有IP的人:带有.NET的Whois客户端 [ ^ ] - 可能不会做你想要的事情虽然

i have a program that generate a list like this of ip's that revised by a network card


31.13.64.1
31.13.64.1
23.65.181.34
23.65.181.34
173.194.113.69
31.13.64.1
69.171.235.16
173.252.110.27
173.194.70.125
195.27.155.40
77.67.96.240
31.13.86.16
192.168.1.1
65.39.148.3



How i convert every ip to it's host name?



I tried the following code

String ip= "31.13.86.16";
String host_name = System.Net.Dns.GetHostEntry(ip).HostName;
file.WriteLine(host_name);



and it keep do exceptions


will i realized according to what you say
that when i pass a IP address that don't have a host name
the return of the GetHostEntry(ip); will be NULL or nothing
or i don't know
so it makes a problem
now how to Handel this?

plz help

解决方案

Most of the addresses you describe there are internet addresses, so they don't have a "host name" in the sense that your code seems to think they do. What you are trying to do is called a Reverse DNS, but those only work within a LAN where the DHCP server (usually your router) has assigned IP addresses to the various attached devices it has contacted directly.

When it comes to the internet, things are not so clear cut, and the hostname isn't applicable, because you can't use it - you can't access a computer via it's hostname through the ip address via their router. Partly, this is for security reasons: would you want a website trawling through your computer directly?

Instead, with IP addresses, it's a domain name you are probably looking for. In the case of your first address, you are probably trying to find the domain name "facebook.com". Again there are problems in that a single IP address may host a number of domains, so there is no one "host name" to return.

There is no centralised lookup service for IP-to-Domain translation - if you want to do that, you will have to visit the IP and see what site it returns...
There are services like whois.com who can tell you who owns the IP though: Whois Client with .NET[^] - probably won't do what you want though.


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

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