3

Possible Duplicate:
How to get domain name from Given IP in C#?

How can i convert ip address in int format to string format. for example, i have this ip address in int format, 173.194.38.138 and i want to convert to string www.rugadingku.blogspot.com. I saw a lots of example on how to convert ip string to int, but not int to string.

Community
  • 1
  • 1
Lynx
  • 259
  • 1
  • 9
  • 26
  • well, you need to build up a [lookup table](http://en.wikipedia.org/wiki/Lookup_table) – BrOSs Dec 10 '12 at 04:50
  • You know that one IP can be shared among many, many hosts, right? – Joel Coehoorn Dec 10 '12 at 04:54
  • 4
    http://stackoverflow.com/questions/3252845/how-to-get-domain-name-from-given-ip-in-c – Habib Dec 10 '12 at 04:55
  • Note: No solution listed here is guaranteed to work. Doing this relies on reverse-DNS, which a particular IP address may or may not have setup. Also, you may get an unexpected hostname because an IP can be tied to multiple DNS names/domains – Earlz Dec 10 '12 at 05:06

2 Answers2

5

you can use this code to convert IP Address to HostName :

IPHostEntry IpToDomainName = Dns.GetHostEntry("173.194.38.138");
string hostname =IpToDomainName.HostName;

Dns.GetHostByAddress

also you can use this way :

 System.Net.IPHostEntry ip = System.Net.Dns.GetHostByAddress("173.194.38.138");
 string hostname = ip.HostName;
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
0

Try this:not tested

visit http://www.dijksterhuis.org/converting-an-ip-address-to-a-hostname-and-back-with-c/

// Map an IP address to a hostname

IPHostEntry IpToDomainName = Dns.GetHostEntry("209.85.173.99");
Console.WriteLine("DomainName: {0}", IpToDomainName.HostName);

Also try this:

public static string getDNSName(string myIP)
{
 System.Net.IPHostEntry ip = System.Net.Dns.GetHostByAddress(myIP);
 return ip.HostName;
}
sajanyamaha
  • 3,119
  • 2
  • 26
  • 44