文件名称:动态改变IP
文件大小:2KB
文件格式:CS
更新时间:2021-05-07 11:54:06
C#
本文件是C#代码片断 public Form1() { InitializeComponent(); } int i = 0; int j = 0; string[] proxys; #region 改变代理 [DllImport("wininet.dll", SetLastError = true)] private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength); /// public void RefreshIESettings(string strProxy) { const int INTERNET_OPTION_PROXY = 38; const int INTERNET_OPEN_TYPE_PROXY = 3; Struct_INTERNET_PROXY_INFO struct_IPI; // Filling in structure struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY; struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy); struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local"); // Allocating memory IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)); // Converting structure to IntPtr Marshal.StructureToPtr(struct_IPI, intptrStruct, true); bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI)); } #endregion private void Form1_Load(object sender, EventArgs e) { proxys = File.ReadAllLines("C:/proxy.txt"); } private void timer1_Tick(object sender, EventArgs e) { if (i < proxys.Length) { label2.Text = proxys[i]; label9.Text = i.ToString(); label3.Text = "waiting..."; RefreshIESettings(proxys[i]); webBrowser1.Navigate("http://www.imwq.net"); timer1.Enabled = false; i++; } else { timer1.Enabled = false; button1.Text = "结束"; } } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { label3.Text = "ok..."; timer1.Enabled = true; } private void button1_Click(object sender, EventArgs e) { timer1.Enabled = true; } } struct Struct_INTERNET_PROXY_INFO { public int dwAccessType; public IntPtr proxy; public IntPtr proxyBypass; };