【发布时间】:2010-10-17 12:50:23
【问题描述】:
您可以使用域查询一个网站,它将返回该 IP 上托管的所有网站的列表。我记得 C# 中有一个方法类似于 ReturnAddresses 或类似的东西。有谁知道这是怎么做到的?查询主机名或 IP 并返回主机名列表(即托管在同一服务器上的其他网站)?
网址是:http://www.yougetsignal.com/tools/web-sites-on-web-server/
【问题讨论】:
您可以使用域查询一个网站,它将返回该 IP 上托管的所有网站的列表。我记得 C# 中有一个方法类似于 ReturnAddresses 或类似的东西。有谁知道这是怎么做到的?查询主机名或 IP 并返回主机名列表(即托管在同一服务器上的其他网站)?
网址是:http://www.yougetsignal.com/tools/web-sites-on-web-server/
【问题讨论】:
看完cmets,bobince肯定是对的,这两个应该一起使用。为获得最佳结果,您应该在此处使用反向 DNS 查找以及使用被动 DNS 复制。
string IpAddressString = "208.5.42.49"; //eggheadcafe
try
{
IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
// Get the IP address list that resolves to the host names contained in
// the Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
String[] alias = hostInfo.Aliases;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nAliases :");
for(int index=0; index < alias.Length; index++) {
Console.WriteLine(alias[index]);
}
Console.WriteLine("\nIP address list : ");
for(int index=0; index < address.Length; index++) {
Console.WriteLine(address[index]);
}
}
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(FormatException e)
{
Console.WriteLine("FormatException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
感谢http://www.eggheadcafe.com/community/aspnet/2/83624/system-dns-gethostbyaddre.aspx
【讨论】:
Jeremy 的回答基于Reverse DNS,这是查找 IP->主机名的常规编程方式。它依赖于为该服务器设置的 PTR 记录;这通常但并不总是设置为有用的东西。
例如查找 thedailywtf.com,您将获得 74.50.106.245,但由于“245.106.50.74.in-addr.arpa”没有 PTR 记录,Dns.GetHostEntry() 不会返回任何内容有用。
同样,许多服务器场只会为您提供一个通用主机名,例如 123.45.67.89-dedicated.bigexamplehost.com。
yougetsignal 所做的不同,它是“被动 DNS 复制”。他们运行一些人们正在查询的 DNS 服务器,并记住每个被查找的主机名。然后你可以通过返回的地址查询他们过去的查找记录。将 74.50.106.245 放入 yougetsignal 中,您将获得一个主机名列表,这些主机名以前在人们查询时解析到 dailywtf 服务器,与反向 DNS PTR 条目无关。
【讨论】:
反向 DNS 与您所要求的不同(哪些站点托管在同一台服务器上)。反向 DNS 通常不会像您预期的那样工作(请参阅 bobince 的回答)。
为了能够识别主机中的其他网站,您需要建立一个庞大的数据库并尽可能多地存储 DNS 记录,然后关联 IP 地址。
查看:http://www.domaintools.com/reverse-ip/
他们正在按照我所说的方式执行此操作,这是获得准确结果的唯一方法。显然,关联和抓取/生成数据需要时间、CPU、带宽和空间。
【讨论】: