I need to get a domain name if I have an IP address (e.g. I type 209.85.129.103 and the program should find out that is the Google address)
如果我有IP地址,我需要获得一个域名(例如我输入209.85.129.103,程序应该知道这是Google地址)
As far as I've figured out is get the hostname:
据我所知,得到主机名:
IPHostEntry IpToDomainName = Dns.GetHostEntry("209.85.129.103");
string HostName = IpToDomainName.HostName; //it returns "fk-in-f103.1e100.net"
but it's not that I want. I don't know how to achieve that. Any ideas will be helpful
但这不是我想要的。我不知道如何实现这一目标。任何想法都会有所帮助
1 个解决方案
#1
1
I guess you're talking about getting the top-level domain name from the host name? The TLD is just the last two dot-separated parts of the full host name, so a function would look like this:
我想你在谈论从主机名获取*域名? TLD只是完整主机名的最后两个以点分隔的部分,因此函数将如下所示:
public static string GetTopLevelDomain(string hostName)
{
int lastDot = hostName.LastIndexOf('.');
if (lastDot < 0)
return hostName;
int previousDot = hostName.LastIndexOf('.', lastDot - 1);
return (previousDot >= 0) ? hostName.Substring(previousDot + 1) : hostName;
}
If you're actually trying to figure out who owns the domain, you have to use a whois lookup. Here's a whois example in C#. The information just comes back as plain text; keep in mind that it won't necessarily even tell you the real person or company who owns it, sometimes that information is private and all you'll get is the registrar (like GoDaddy).
如果您实际上想确定谁拥有该域名,您必须使用whois查找。这是C#中的一个whois示例。信息只是以纯文本形式返回;请记住,它甚至不一定会告诉你拥有它的真实的人或公司,有时候这些信息是私密的,而你所得到的只是注册商(如GoDaddy)。
Also, different whois servers will give different information and different areas; for example you can get information on a U.S. domain with ARIN, but for European domains you need to use RIPE instead. Honestly I hope that this isn't what you're trying to do because you're going to find that it's a quite a tar-pit; there's no simple way of reliably determining that Domain X is owned by Company Y.
此外,不同的whois服务器将提供不同的信息和不同的区域;例如,您可以使用ARIN获取有关美国域名的信息,但对于欧洲域名,您需要使用RIPE。老实说,我希望这不是你想要做的,因为你会发现它是一个相当焦油的坑;没有简单的方法可靠地确定域X是由Y公司拥有的。
#1
1
I guess you're talking about getting the top-level domain name from the host name? The TLD is just the last two dot-separated parts of the full host name, so a function would look like this:
我想你在谈论从主机名获取*域名? TLD只是完整主机名的最后两个以点分隔的部分,因此函数将如下所示:
public static string GetTopLevelDomain(string hostName)
{
int lastDot = hostName.LastIndexOf('.');
if (lastDot < 0)
return hostName;
int previousDot = hostName.LastIndexOf('.', lastDot - 1);
return (previousDot >= 0) ? hostName.Substring(previousDot + 1) : hostName;
}
If you're actually trying to figure out who owns the domain, you have to use a whois lookup. Here's a whois example in C#. The information just comes back as plain text; keep in mind that it won't necessarily even tell you the real person or company who owns it, sometimes that information is private and all you'll get is the registrar (like GoDaddy).
如果您实际上想确定谁拥有该域名,您必须使用whois查找。这是C#中的一个whois示例。信息只是以纯文本形式返回;请记住,它甚至不一定会告诉你拥有它的真实的人或公司,有时候这些信息是私密的,而你所得到的只是注册商(如GoDaddy)。
Also, different whois servers will give different information and different areas; for example you can get information on a U.S. domain with ARIN, but for European domains you need to use RIPE instead. Honestly I hope that this isn't what you're trying to do because you're going to find that it's a quite a tar-pit; there's no simple way of reliably determining that Domain X is owned by Company Y.
此外,不同的whois服务器将提供不同的信息和不同的区域;例如,您可以使用ARIN获取有关美国域名的信息,但对于欧洲域名,您需要使用RIPE。老实说,我希望这不是你想要做的,因为你会发现它是一个相当焦油的坑;没有简单的方法可靠地确定域X是由Y公司拥有的。