Get domain name based on IP address

I need to get a domain name if I have an IP address (for example, I type 209.85.129.103 and the program should find out that this is a Google address)

As I understand it, get the host name:

IPHostEntry IpToDomainName = Dns.GetHostEntry("209.85.129.103");
string HostName = IpToDomainName.HostName; //it returns "fk-in-f103.1e100.net"

but that’s not what I want. I do not know how to achieve this. Any ideas would be helpful.

+3
source share
1 answer

I think you are talking about getting a top level domain name from a host name? TLDs are just the last two parts separated by periods in the full host name, so the function will look like this:

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;
}

, , whois. whois #. ; , , , , , , - (, GoDaddy).

, whois ; , ARIN, RIPE. , , , , , ; , X Y.

+1

Source: https://habr.com/ru/post/1736819/


All Articles