开发者

how to convert ip address to url with VB.NET OR C#

开发者 https://www.devze.com 2023-01-27 14:13 出处:网络
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 a

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

0

精彩评论

暂无评论...
验证码 换一张
取 消