如何获取的HttpWebRequest连接到服务器的IP地址? [英] How to get IP address of the server that HttpWebRequest connected to?
本文介绍了如何获取的HttpWebRequest连接到服务器的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DSN可以返回多个IP地址,因此而不是使用DNS解析我的请求后获得的IP地址我想我的HttpWebRequest连接到IP。
DSN can return multiple IP addresses so rather then using DNS resolving to get the IP address after my request I want to get the IP that my HttpWebRequest connected to.
反正有做到这一点在.NET 3.5?
Is there anyway to do this in .NET 3.5?
例如,当我做一个简单的Web请求www.microsoft.com我想知道哪些IP地址,连接发送HTTP请求,我想这个编程(不通过的Wireshark等。)
For example when I do a simple web request to www.microsoft.com I want to learn that which IP address it connected to send the HTTP request, I want to this programmatically (not via Wireshark etc.)
推荐答案
在这里你去
static void Main(string[] args)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
req.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPoint1);
Console.ReadKey();
}
public static IPEndPoint BindIPEndPoint1(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
{
string IP = remoteEndPoint.ToString();
return remoteEndPoint;
}
使用remoteEndPoint收集所需的数据。
Use remoteEndPoint to collect the data you want.
这篇关于如何获取的HttpWebRequest连接到服务器的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文