I want to convert ip address to url. But i can't figure it out how to开发者_StackOverflow中文版.
It's not entirely clear what you want - an example would have been helpful - but something as simple as:
string url = "http://" + ipAddress;
would quite possibly be enough.
EDIT: Okay, it sounds like you're trying to find the name for an IP address. In some ways that's quite simple:
IPHostEntry entry = Dns.GetHostEntry("72.29.94.50");
Console.WriteLine(entry.HostName);
However, this doesn't print eggheadcafe.com. It prints something entirely different:
72.29.94.50.static.dimenoc.com
That's entirely correct in terms of a reverse DNS lookup (run "nslookup 72.29.94.50" to see the same result)... but it's not what you were looking for.
The problem is that I believe this eggheadcafe.com is served by virtual hosting - although eggheadcafe.com is served on that IP address, so are other websites (at least potentially). When you visit eggheadcafe.com in your browser, it resolves to that IP address but also specifies the host name in an HTTP header.
Not sure what you want to achieve but guess you need to resolve a host name from IP.
In this case you can use Dns.GetHostEntry
method.
There are possibility of multiple website hosted on single IP. But you can get default using
IPHostEntry IpEntry = Dns.GetHostByAddress(ip);
return iphostentry.HostName.ToString();
Following might helpful to start with:
http://www.c-sharpcorner.com/UploadFile/uchukamen/IPAddHostConverter12052005041212AM/IPAddHostConverter.aspx
精彩评论