c#換ip代理源碼

很多朋友都想如何提高自己的網站流量,可是都沒有什麼好的辦法
經過很長時間的研究,在C#中實現了,當然了,這部分代碼其中一部分是網上的,不是原創。


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Net;
namespace WebSock
{
 /// <summary>
 /// Form1 的摘要說明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.GroupBox groupBox1;
  private AxSHDocVw.AxWebBrowser axWebBrowser1;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Button button2;
  private System.Windows.Forms.OpenFileDialog openFileDialog1;
  private System.Windows.Forms.Timer timer1;
  private System.ComponentModel.IContainer components;
  private System.Windows.Forms.StatusBar statusBar1;
  private System.Windows.Forms.StatusBarPanel statusBarPanel1;
  private System.Windows.Forms.GroupBox groupBox2;
  private System.Windows.Forms.GroupBox groupBox3;
  private System.Windows.Forms.GroupBox groupBox4;
  private System.Windows.Forms.Button button3;
  ArrayList arrText = new ArrayList();
  int Total = 0;
  int i,k=0;
  private System.Windows.Forms.GroupBox groupBox5;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.TextBox txtWebUrl;
  private const string TitleInfo = "程序製作紅色銀狐";
  private System.Windows.Forms.ListBox listBox1;
  private string strUrl = "";
  public Form1()
  {
   //
   // Windows 窗體設計器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
   //
  }


  /// <summary>
  /// 清理所有正在使用的資源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null) 
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }


  #region Windows 窗體設計器生成的代碼
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
   this.groupBox1 = new System.Windows.Forms.GroupBox();
   this.groupBox3 = new System.Windows.Forms.GroupBox();
   this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
   this.groupBox2 = new System.Windows.Forms.GroupBox();
   this.listBox1 = new System.Windows.Forms.ListBox();
   this.button1 = new System.Windows.Forms.Button();
   this.button2 = new System.Windows.Forms.Button();
   this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
   this.timer1 = new System.Windows.Forms.Timer(this.components);
   this.statusBar1 = new System.Windows.Forms.StatusBar();
   this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
   this.groupBox4 = new System.Windows.Forms.GroupBox();
   this.button3 = new System.Windows.Forms.Button();
   this.groupBox5 = new System.Windows.Forms.GroupBox();
   this.label1 = new System.Windows.Forms.Label();
   this.txtWebUrl = new System.Windows.Forms.TextBox();
   this.groupBox1.SuspendLayout();
   this.groupBox3.SuspendLayout();
   ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
   this.groupBox2.SuspendLayout();
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
   this.groupBox4.SuspendLayout();
   this.groupBox5.SuspendLayout();
   this.SuspendLayout();
   // 
   // groupBox1
   // 
   this.groupBox1.Controls.Add(this.groupBox3);
   this.groupBox1.Controls.Add(this.groupBox2);
   this.groupBox1.Location = new System.Drawing.Point(0, 0);
   this.groupBox1.Name = "groupBox1";
   this.groupBox1.Size = new System.Drawing.Size(810, 440);
   this.groupBox1.TabIndex = 0;
   this.groupBox1.TabStop = false;
   // 
   // groupBox3
   // 
   this.groupBox3.Controls.Add(this.axWebBrowser1);
   this.groupBox3.Location = new System.Drawing.Point(312, 8);
   this.groupBox3.Name = "groupBox3";
   this.groupBox3.Size = new System.Drawing.Size(490, 424);
   this.groupBox3.TabIndex = 2;
   this.groupBox3.TabStop = false;
   this.groupBox3.Text = "瀏覽器";
   // 
   // axWebBrowser1
   // 
   this.axWebBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
   this.axWebBrowser1.ContainingControl = this;
   this.axWebBrowser1.Enabled = true;
   this.axWebBrowser1.Location = new System.Drawing.Point(8, 16);
   this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
   this.axWebBrowser1.Size = new System.Drawing.Size(474, 400);
   this.axWebBrowser1.TabIndex = 0;
   // 
   // groupBox2
   // 
   this.groupBox2.Controls.Add(this.listBox1);
   this.groupBox2.Location = new System.Drawing.Point(8, 8);
   this.groupBox2.Name = "groupBox2";
   this.groupBox2.Size = new System.Drawing.Size(296, 424);
   this.groupBox2.TabIndex = 1;
   this.groupBox2.TabStop = false;
   this.groupBox2.Text = "代理IP地址";
   // 
   // listBox1
   // 
   this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
   this.listBox1.ItemHeight = 12;
   this.listBox1.Location = new System.Drawing.Point(8, 16);
   this.listBox1.Name = "listBox1";
   this.listBox1.Size = new System.Drawing.Size(280, 398);
   this.listBox1.TabIndex = 2;
   // 
   // button1
   // 
   this.button1.Location = new System.Drawing.Point(310, 16);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(176, 32);
   this.button1.TabIndex = 1;
   this.button1.Text = "載入代理IP";
   this.button1.Click += new System.EventHandler(this.button1_Click_1);
   // 
   // button2
   // 
   this.button2.Location = new System.Drawing.Point(486, 16);
   this.button2.Name = "button2";
   this.button2.Size = new System.Drawing.Size(176, 32);
   this.button2.TabIndex = 2;
   this.button2.Text = "開始刷流量";
   this.button2.Click += new System.EventHandler(this.button2_Click);
   // 
   // timer1
   // 
   this.timer1.Interval = 10000;
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
   // 
   // statusBar1
   // 
   this.statusBar1.Dock = System.Windows.Forms.DockStyle.None;
   this.statusBar1.Location = new System.Drawing.Point(0, 552);
   this.statusBar1.Name = "statusBar1";
   this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
                        this.statusBarPanel1});
   this.statusBar1.ShowPanels = true;
   this.statusBar1.Size = new System.Drawing.Size(810, 24);
   this.statusBar1.TabIndex = 3;
   // 
   // statusBarPanel1
   // 
   this.statusBarPanel1.Width = 820;
   // 
   // groupBox4
   // 
   this.groupBox4.Controls.Add(this.button3);
   this.groupBox4.Controls.Add(this.button2);
   this.groupBox4.Controls.Add(this.button1);
   this.groupBox4.Location = new System.Drawing.Point(0, 496);
   this.groupBox4.Name = "groupBox4";
   this.groupBox4.Size = new System.Drawing.Size(810, 56);
   this.groupBox4.TabIndex = 4;
   this.groupBox4.TabStop = false;
   this.groupBox4.Text = "操作區";
   // 
   // button3
   // 
   this.button3.Location = new System.Drawing.Point(134, 16);
   this.button3.Name = "button3";
   this.button3.Size = new System.Drawing.Size(176, 32);
   this.button3.TabIndex = 3;
   this.button3.Text = "從網絡獲取代理IP";
   this.button3.Click += new System.EventHandler(this.button3_Click);
   // 
   // groupBox5
   // 
   this.groupBox5.Controls.Add(this.label1);
   this.groupBox5.Controls.Add(this.txtWebUrl);
   this.groupBox5.Location = new System.Drawing.Point(0, 444);
   this.groupBox5.Name = "groupBox5";
   this.groupBox5.Size = new System.Drawing.Size(810, 48);
   this.groupBox5.TabIndex = 5;
   this.groupBox5.TabStop = false;
   this.groupBox5.Text = "要刷網站地址";
   // 
   // label1
   // 
   this.label1.Location = new System.Drawing.Point(16, 21);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(56, 16);
   this.label1.TabIndex = 1;
   this.label1.Text = "網站地址";
   // 
   // txtWebUrl
   // 
   this.txtWebUrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
   this.txtWebUrl.Location = new System.Drawing.Point(80, 16);
   this.txtWebUrl.Name = "txtWebUrl";
   this.txtWebUrl.Size = new System.Drawing.Size(720, 21);
   this.txtWebUrl.TabIndex = 0;
   this.txtWebUrl.Text = "http://www.51solve.com/";
   // 
   // Form1
   // 
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(810, 575);
   this.Controls.Add(this.groupBox5);
   this.Controls.Add(this.groupBox4);
   this.Controls.Add(this.statusBar1);
   this.Controls.Add(this.groupBox1);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
   this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
   this.MaximizeBox = false;
   this.Name = "Form1";
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "網站流量訪問程序製作:紅色銀狐";
   this.groupBox1.ResumeLayout(false);
   this.groupBox3.ResumeLayout(false);
   ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
   this.groupBox2.ResumeLayout(false);
   ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
   this.groupBox4.ResumeLayout(false);
   this.groupBox5.ResumeLayout(false);
   this.ResumeLayout(false);


  }
  #endregion


  /// <summary>
  /// 應用程序的主入口點。
  /// </summary>
  [STAThread]
  static void Main() 
  {
   Application.Run(new Form1());
  }
  //定義結構體代理信息
  public struct Struct_INTERNET_PROXY_INFO 
  { 
   public int dwAccessType; 
   public IntPtr proxy; 
   public IntPtr proxyBypass; 
  }; 
  [DllImport("wininet.dll", SetLastError = true)] 
  private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);


  private 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)); 
  } 


  private void StartShua() 
  { 
   statusBar1.Panels[0].Text = "正在使用" + arrText[k].ToString() + "代理IP訪問網站";
   this.listBox1.SetSelected(k,true);
   RefreshIESettings(arrText[k].ToString()); 
   System.Object nullObject = 0; 
   string strTemp = String.Empty; 
   System.Object nullObjStr = strTemp;
   axWebBrowser1.Navigate(strUrl, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
   k+=1;
   if(k>=i)k=0;
  }
  private void button1_Click_1(object sender, System.EventArgs e)
  {
   arrText.Clear();
   i = 0;
   if(openFileDialog1.ShowDialog() ==DialogResult.OK)
   {
    string strPath,strLine = "";
    strPath = openFileDialog1.FileName.ToString();
    StreamReader sr = new StreamReader(strPath);
    while(strLine != null)
    {
     strLine = sr.ReadLine();
     if(strLine != null)
     {
      i+=1;
      arrText.Add(strLine);
      listBox1.Items.Add(strLine);
     }
    }
    sr.Close();
   }
  }
  private void timer1_Tick(object sender, System.EventArgs e)
  {
   StartShua();
  }


  private void button2_Click(object sender, System.EventArgs e)
  {
   Total = listBox1.Items.Count;
   strUrl = txtWebUrl.Text;
   if(button2.Text == "開始刷流量")
   {
    if(i == 0 && Total == 0)return;
    if(strUrl.Length == 0)return;
    StartShua();
    button2.Text = "停止刷流量";
    timer1.Enabled = true;
    timer1.Start();
    button1.Enabled = false;
    button3.Enabled = false;
   }
   else
   {
    timer1.Stop();
    timer1.Enabled = false;
    button2.Text = "開始刷流量";
    button1.Enabled = true;
    button3.Enabled = true;
    arrText.Clear();
   }
  }


  private void button3_Click(object sender, System.EventArgs e)
  {
   arrText.Clear();
   i = 0;
   listBox1.Items.Clear();
   string strHtml = "";
   string strPort = "";
   string strResultIP = "";
   long PosB = 0;
   long PosA = 0;
   long PosC = 0;
   string Url = "http://www.pass-e.com/proxy/";
   try
   {
    strHtml = GetHtml(Url);
    strHtml = checkStr(strHtml);
    strHtml = strHtml.ToLower();
    PosA = strHtml.IndexOf("list",0);
    //MessageBox.Show(GetHtml(Url));
    while(PosA>0)
    {
     i+=1;
     PosB = strHtml.IndexOf(",",(int)PosA);
     strResultIP = strHtml.Substring((int)PosA,(int)PosB-(int)PosA);
     strResultIP = strResultIP.Replace("list","");
     PosC = strHtml.IndexOf(",",(int)PosB+1);
     strPort = strHtml.Substring((int)PosB,(int)PosC-(int)PosB);
     strPort = strPort.Replace(",","");
     listBox1.Items.Add(strResultIP+":"+strPort);
     PosA = strHtml.IndexOf("list",(int)PosC);
     arrText.Add(strResultIP+":"+strPort);
    }
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.Message,TitleInfo,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
   }
  }
  public string checkStr(string html) 
  { 
   string str = Convert.ToString((char)34);
   
   Regex regex1 = new Regex(@"<mce:script[/s/S]+</script *><!--
", RegexOptions.IgnoreCase); 
   Regex regex2 = new Regex(@" href *= *[/s/S]*script *:", RegexOptions.IgnoreCase); 
   Regex regex3 = new Regex(@" no[/s/S]*=", RegexOptions.IgnoreCase); 
   Regex regex4 = new Regex(@"<iframe[/s/S]+</iframe *>", RegexOptions.IgnoreCase); 
   Regex regex5 = new Regex(@"<frameset[/s/S]+</frameset *>", RegexOptions.IgnoreCase); 
   Regex regex6 = new Regex(@"/<img[^/>]+/>", RegexOptions.IgnoreCase);  
   Regex regex7 = new Regex(@"</p>", RegexOptions.IgnoreCase); 
   Regex regex8 = new Regex(@"<p>", RegexOptions.IgnoreCase); 
   Regex regex9 = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);
   html = html.Replace("/r/n","");
   //html = regex1.Replace(html, ""); //過濾<script>
// --></mce:script>標記 
   html = regex2.Replace(html, ""); //過濾href=javascript: (<A>) 屬性 
   html = regex3.Replace(html, " _disibledevent="); //過濾其它控件的on...事件 
   html = regex4.Replace(html, ""); //過濾iframe 
   html = regex5.Replace(html, ""); //過濾frameset 
   html = regex6.Replace(html, ""); //過濾frameset 
   html = regex7.Replace(html, ""); //過濾frameset 
   html = regex8.Replace(html, ""); //過濾frameset 
   html = regex9.Replace(html, ""); 
   html = html.Replace(" ", ""); 
   html = html.Replace("</strong>", ""); 
   html = html.Replace("<strong>", "");
   html = html.Replace("/n","");
   html = html.Replace(str ,"");
   html = html.Replace("}" ,"");
   html = html.Replace("(" ,"");
   html = html.Replace(")" ,"");
   //html = html.Replace(";" ,"");
   html = html.Replace("'" ,"");
   html = html.Replace("&nbsp;" ,"");
   html = html.Replace(" ","");
   return html; 
  }
  public string GetHtml(string myUrl) 
  { 
   HttpWebRequest myHttpWebRequest; 
    
   HttpWebResponse myHttpWebResponse; 
    
   //string Html; 
    
   try 
   { 
        
    string URL = myUrl; 
        
    Uri myUri = new Uri(myUrl); 
        
    WebRequest myWebRequest = WebRequest.Create(URL); 
        
    //使用Creat方法創建WebRequest實例 
        
    myHttpWebRequest = (HttpWebRequest)myWebRequest; 
        
    //實現WebRequest類型和HttpWebRequest類型的轉換 
        
    WebResponse myWebResponse = myHttpWebRequest.GetResponse(); 
        
    //獲得響應信息 
        
    myHttpWebResponse = (HttpWebResponse)myWebResponse; 
        
    Stream myStream = myHttpWebResponse.GetResponseStream(); 
        
    //獲得從當前Internet資源返回的響應流數據 
        
    StreamReader srReader = new StreamReader(myStream, Encoding.Default); 
        
    //利用獲得的響應流和系統缺省編碼來初始化StreamReader實例。 
        
    string sTemp = srReader.ReadToEnd(); 
        
    //從響應流從讀取數據 
        
    srReader.Close(); 
        
    return sTemp; 
   } 
    
    //顯示讀取的數據 ( ) 
    
   catch (WebException WebExcp) 
   { 
        
    return WebExcp.Message.ToString(); 
   } 
  } 
 }


}










通過它的實現,只要你有足夠的代理IP那麼你的網站流量變飛速的提升。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章