从IP地址获取URL [英] Get URL from IP Address
本文介绍了从IP地址获取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有IP地址,在C ++(Windows)中是否可以获取网站的网址?谢谢您的帮助或指导.
Is there a way in C++ (Windows) to get the URL of a website if I have the IP address? Thank you for any help or direction.
推荐答案
尽管您可能能够从IP地址获取网站的URL,但不能确定你有合适的人.
多个网站可以托管在一个IP地址上,因此,您最好希望的是反向DNS查找将为您提供网站名称-它可能仅为您提供服务器名称.
示例:dig www.google.com
为我提供了一个具有6个IP地址的CNAME:
While you might be able to get the URL of a website from an IP address, you can''t be sure that you''ve got the right one.
Multiple websites can be hosted on a single IP address, so the best you can hope for is that a reverse DNS lookup will give you the name of a website - it might just give you a server name.
Example:dig www.google.com
gives me a CNAME with 6 IP addresses:
www.google.com. 86399 IN CNAME www.l.google.com.
www.l.google.com. 299 IN A 209.85.146.105
www.l.google.com. 299 IN A 209.85.146.99
www.l.google.com. 299 IN A 209.85.146.104
www.l.google.com. 299 IN A 209.85.146.106
www.l.google.com. 299 IN A 209.85.146.147
www.l.google.com. 299 IN A 209.85.146.103
在这些地址中的第一个(dig -x 209.85.146.105
)上进行反向DNS查找会给我一个不同的名称:
Reverse DNS lookup on the first of these addresses (dig -x 209.85.146.105
) gives me a different name:
105.146.85.209.in-addr.arpa. 86400 IN PTR bru01s01-in-f105.1e100.net.
-没有任何关于任何网站的有用信息.
- which doesn''t say anything useful about any websites.
您不能.
URL与IP之间的关系不是1/1,URL比IP更抽象的概念:URL是为不同目的量身定制的:URL告诉您想要的页面,IP告诉在哪里可以找到它.
IP名称和IP地址id之间的映射由称为域名系统"的层次结构冗余分布式数据库管理,该数据库的API由get_host_by_name
和get_name_by_host
函数表示.
DNS返回呼叫的任何方式或其他都不取决于您的方式,并且DNS标准不需要该呼叫来表示对合(因此get_name_by_host(get_host_by_name(name)) != name
),
基本上,在这个世界上,甚至还有许多无关的人都以史密斯"作为姓氏,您的疑问听起来像是是否有史密斯的名字?".
You can''t.
The relation between URL and IP is not 1/1, and URLs are more abstract concept than IPs: They are tailored to different purposes: The URL tells WHAT page you want, the IP tells WHERE it can be found.
The mapping between IP names and IP addresses id managed by a hierarchical redundant distributed database called "Domain Name System", whose API are represented by theget_host_by_name
andget_name_by_host
functions.
Whatever the DNS returns to a call or the other does not depend on you, ant it is not required by the DNS standard for that calls to represent an involution (henceget_name_by_host(get_host_by_name(name)) != name
),
Basically you question sounds like "Is there a way to get the name of Smith?", in a world that has many even unrelated people having "Smith" as a surname.
嗯,那无法获取URL,而是将IP地址(二进制)作为标准IP地址获取为字符串,并在数字之间加上点号.
哦,顺便说一句,sockAddr.sin_addr.s_addr字段在您询问有关比较地址的另一个问题中可能对您确实有用.
uh, that doesn''t get a URL, it gets the IP address (binary) as a standard IP address as a string of characters with the dots between the numbers.
Oh, BTW, the sockAddr.sin_addr.s_addr field might be real useful to you in the other question you asked about comparing addresses.
这篇关于从IP地址获取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文