我想知道实际使用的源IP,所以我想从Web实例获取源IP地址。 如何找到实际使用的ip源? 我想在不使用网络分析器的情况下从visual studio进行检查(例如wireshark)
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
List<WebClientEx> li = new List<WebClientEx>();
li.Add(new WebClientEx() { ipEndPoint = new IPEndPoint(IPAddress.Parse("Source IP Address 1"), 0) });
li.Add(new WebClientEx() { ipEndPoint = new IPEndPoint(IPAddress.Parse("Source IP Address 2"), 0) });
li.Add(new WebClientEx() { ipEndPoint = new IPEndPoint(IPAddress.Parse("Source IP Address 3"), 0) });
foreach (WebClientEx web in li)
{
string html = web.DownloadString("https://www.ugtop.com/spill.shtml");
Debug.WriteLine("xxxxxxxxx"); //I want to know source ip actually used, so I want to get source ip address from web instance.
}
}
}
public class WebClientEx : WebClient
{
public IPEndPoint ipEndPoint;
public IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) => ipEndPoint;
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
request.ConnectionGroupName = ipEndPoint.ToString();
request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
return request;
}
}
}