Take the 2-minute tour ×

Suppose I am retrieving a url as follows:

string url = "http://www.somesite.com/somepage.html"
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

Is there a way I can see the IP address of the destination url? Does it require a separate call?


share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Look at the System.Net.Dns class. You can get a list of IP addresses of the host from the Dns.GetHostEntry() method.

share|improve this answer
add comment

Although Dns.GetHostEntry() can get you the IP of the server, in case there are multiple A records for the same host, you'll get them all (also known as round-robin DNS). However, when actually connecting to a web server, client picks one of those IPs.

There doesn't seem to be an exposed way to find out exactly which IP was used when connecting. I've found this information while working on our web monitoring solution at www.justwentdown.com. This info is located in a private field of the web response,


However, because Connection and ServerAddress are private/internal properties, you'll need to use reflection to get the values. I've found this solution to be very useful in those situations.

I've tested it with .NET 4.0. It's a bit messy and may break with future versions of .NET, so I'd recommend adding a unit test.

share|improve this answer
add comment

Your Answer


