动态改变IP
本文件是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; };
- 粉丝: 108
- 资源: 18
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助