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 this in C#?
Querying DNS Click the Windows Start button, then "All Programs" and "Accessories." Right-click on "Command Prompt" and choose "Run as Administrator." Type "nslookup %ipaddress%" in the black box that appears on the screen, substituting %ipaddress% with the IP address for which you want to find the hostname.
Method 2: Using nslookup command This is another method to get the hostname from the IP address. Run the nslookup command with an IP address from which you want to get the hostname. This command works a bit differently from the ping command that is discussed above.
To find the IP address range of a domain, you can use the "dig" or "nslookup" command. For example, if you want to find the IP address range of the domain "example.com", you would use the following command: dig +short example.com The output of this command would be the IP address range of the domain "example.com".
To do this, open the Command Prompt and type "ping" followed by the domain name. For example, to find the IP address for the website "example.com," you would type "ping example.com."
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.
Console.WriteLine("DomainName: {0}", Dns.GetHostEntry("1.1.1.1").HostName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With