I want to get domain name from a given IP. E.g If I give IP as \"172.24.17.85\" I should get only domain name like my domain name is sonata.net.
Any code snippet for
Console.WriteLine("DomainName: {0}", Dns.GetHostEntry("1.1.1.1").HostName);
Have you tried Dns.GetHostEntry?
Example:
using System;
using System.Net;
class Test
{
static void Main(string[] args)
{
IPAddress addr = IPAddress.Parse("69.59.196.211");
IPHostEntry entry = Dns.GetHostEntry(addr);
Console.WriteLine(entry.HostName); // Prints "stackoverflow.com"
}
}
Note that this didn't work for the example you gave... if a reverse DNS lookup doesn't work, I'm not sure what you can do.
I really doubt if this is going to be possible. There could be n
number of domains pointing to a single IP. You can do some research on Reverse DNS lookup.