C# 设置IE浏览器代理

这个小工具可以用来设置 ie浏览器的代理 ip,其实就是去修改注册表相关键值。。

理论上来说 ,只要是 使用ie内核的浏览器都可以,不过我没试。。。

下面上图,上代码,上程序

  1. using System;
     
  2. using System.Collections.Generic;
     
  3. using System.ComponentModel;
     
  4. using System.Data;
     
  5. using System.Drawing;
     
  6. using System.Text;
     
  7. using System.Windows.Forms;
     
  8. using System.Diagnostics;
     
  9. using System.IO;
     

  10.  
  11. namespace SetProxy
     
  12. {
     
  13.     public partial class FormMain : Form
     
  14.     {
     
  15.         public FormMain()
     
  16.         {
     
  17.             InitializeComponent();
     
  18.         }
     

  19.  
  20.         private void btn_SetProxy_Click(object sender, EventArgs e)
     
  21.         {
     
  22.             Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
     
  23.             rk.SetValue("ProxyEnable", 1);
     
  24.             rk.SetValue("ProxyServer", this.txt_ProxyIP.Text);
     
  25.             rk.Close();
     
  26.             MessageBox.Show("代理设置完成...");
     
  27.         }
     

  28.  
  29.         
     

  30.  
  31.         private void button1_Click(object sender, EventArgs e)
     
  32.         {
     
  33.             Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
     

  34.  
  35.             foreach (System.Diagnostics.Process myProcess in myProcesses)
     
  36.             {
     
  37.                 if (myProcess.ProcessName.ToUpper() == "IEXPLORE")
     
  38.                 {
     
  39.                     myProcess.Kill();
     
  40.                 }
     
  41.             }
     
  42.             Process.Start("iexplore.exe", "http://www.baidu.com/s?wd=ip");
     
  43.         }
     

  44.  
  45.         private void btn_UnSet_Click(object sender, EventArgs e)
     
  46.         {
     
  47.             Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
     
  48.             rk.SetValue("ProxyEnable", 0);
     
  49.             rk.Close();
     
  50.             MessageBox.Show("代理已取消...");
     

  51.  

  52.  
  53.         }
     

  54.  
  55.         private void btn_Input_Click(object sender, EventArgs e)
     
  56.         {
     
  57.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
     
  58.             {
     
  59.                 string fn = openFileDialog1.FileName;
     
  60.                     // Create an instance of StreamReader to read from a file.
     
  61.                     // The using statement also closes the StreamReader.
     
  62.                 using (StreamReader sr = new StreamReader(fn))
     
  63.                 {
     
  64.                     String line;
     
  65.                     // Read and display lines from the file until the end of 
     
  66.                     // the file is reached.
     
  67.                     while ((line = sr.ReadLine()) != null)
     
  68.                     {
     
  69.                         string[] temp = line.Split(':');
     
  70.                         ListViewItem item = new ListViewItem(new string [] {temp[0],temp[1] });
     
  71.                         listview_ip.Items.Add(item);
     
  72.                     }
     
  73.                 }
     

  74.  

  75.  
  76.             }
     
  77.         }
     

  78.  
  79.         private void listview_ip_MouseDoubleClick(object sender, MouseEventArgs e)
     
  80.         {
     
  81.             string ip = listview_ip.SelectedItems[0].SubItems[0].Text + ":" + listview_ip.SelectedItems[0].SubItems[1].Text;
     
  82.             Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
     
  83.             rk.SetValue("ProxyEnable", 1);
     
  84.             rk.SetValue("ProxyServer", ip);
     
  85.             rk.Close();
     

  86.  
  87.             Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
     

  88.  
  89.             foreach (System.Diagnostics.Process myProcess in myProcesses)
     
  90.             {
     
  91.                 if (myProcess.ProcessName.ToUpper() == "IEXPLORE")
     
  92.                 {
     
  93.                     myProcess.Kill();
     
  94.                 }
     
  95.             }
     
  96.             Process.Start("iexplore.exe", "http://www.myhack58.com/s?wd=ip");
     
  97.         }
     
  98.     }
     
  99. }
     

可导入代理,双击ip设置代理,也可在 文本框中填入代理设置,代理可以去代理网站抓取,同胞们可以写个代理抓取软件。



我把源码和 程序一起打包,只想要程序的,解压完成后,拷贝出 \SetProxy\bin\Release\SetProxy.exe就可以了。。

再给大家传点我刚检测完的http代理,代理可能几天过后就不能用了,大家自己去抓取。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值