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 = ;
int i,k=;
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(, );
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(, );
this.groupBox1.TabIndex = ;
this.groupBox1.TabStop = false;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.axWebBrowser1);
this.groupBox3.Location = new System.Drawing.Point(, );
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(, );
this.groupBox3.TabIndex = ;
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(, );
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(, );
this.axWebBrowser1.TabIndex = ;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.listBox1);
this.groupBox2.Location = new System.Drawing.Point(, );
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(, );
this.groupBox2.TabIndex = ;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "代理IP地址";
//
// listBox1
//
this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.listBox1.ItemHeight = ;
this.listBox1.Location = new System.Drawing.Point(, );
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(, );
this.listBox1.TabIndex = ;
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "载入代理IP";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// button2
//
this.button2.Location = new System.Drawing.Point(, );
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(, );
this.button2.TabIndex = ;
this.button2.Text = "开始刷流量";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// timer1
//
this.timer1.Interval = ;
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(, );
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(, );
this.statusBar1.TabIndex = ;
//
// statusBarPanel1
//
this.statusBarPanel1.Width = ;
//
// 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(, );
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(, );
this.groupBox4.TabIndex = ;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "操作区";
//
// button3
//
this.button3.Location = new System.Drawing.Point(, );
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(, );
this.button3.TabIndex = ;
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(, );
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(, );
this.groupBox5.TabIndex = ;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "要刷网站地址";
//
// label1
//
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "网站地址";
//
// txtWebUrl
//
this.txtWebUrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtWebUrl.Location = new System.Drawing.Point(, );
this.txtWebUrl.Name = "txtWebUrl";
this.txtWebUrl.Size = new System.Drawing.Size(, );
this.txtWebUrl.TabIndex = ;
this.txtWebUrl.Text = "http://www.51solve.com/";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(, );
this.ClientSize = new System.Drawing.Size(, );
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 = ;
const int INTERNET_OPEN_TYPE_PROXY = ; 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[].Text = "正在使用" + arrText[k].ToString() + "代理IP访问网站";
this.listBox1.SetSelected(k,true);
RefreshIESettings(arrText[k].ToString());
System.Object nullObject = ;
string strTemp = String.Empty;
System.Object nullObjStr = strTemp;
axWebBrowser1.Navigate(strUrl, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
k+=;
if(k>=i)k=;
}
private void button1_Click_1(object sender, System.EventArgs e)
{
arrText.Clear();
i = ;
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+=;
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 == && Total == )return;
if(strUrl.Length == )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 = ;
listBox1.Items.Clear();
string strHtml = "";
string strPort = "";
string strResultIP = "";
long PosB = ;
long PosA = ;
long PosC = ;
string Url = "http://www.pass-e.com/proxy/";
try
{
strHtml = GetHtml(Url);
strHtml = checkStr(strHtml);
strHtml = strHtml.ToLower();
PosA = strHtml.IndexOf("list",);
//MessageBox.Show(GetHtml(Url));
while(PosA>)
{
i+=;
PosB = strHtml.IndexOf(",",(int)PosA);
strResultIP = strHtml.Substring((int)PosA,(int)PosB-(int)PosA);
strResultIP = strResultIP.Replace("list","");
PosC = strHtml.IndexOf(",",(int)PosB+);
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)); 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(" " ,"");
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那么你的网站流量变飞速的提升。
很多朋友都想如何提高自己的网站流量,可是都没有什么好的办法
经过很长时间的研究,在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 = ;
int i,k=;
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(, );
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(, );
this.groupBox1.TabIndex = ;
this.groupBox1.TabStop = false;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.axWebBrowser1);
this.groupBox3.Location = new System.Drawing.Point(, );
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(, );
this.groupBox3.TabIndex = ;
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(, );
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(, );
this.axWebBrowser1.TabIndex = ;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.listBox1);
this.groupBox2.Location = new System.Drawing.Point(, );
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(, );
this.groupBox2.TabIndex = ;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "代理IP地址";
//
// listBox1
//
this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.listBox1.ItemHeight = ;
this.listBox1.Location = new System.Drawing.Point(, );
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(, );
this.listBox1.TabIndex = ;
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "载入代理IP";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// button2
//
this.button2.Location = new System.Drawing.Point(, );
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(, );
this.button2.TabIndex = ;
this.button2.Text = "开始刷流量";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// timer1
//
this.timer1.Interval = ;
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(, );
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(, );
this.statusBar1.TabIndex = ;
//
// statusBarPanel1
//
this.statusBarPanel1.Width = ;
//
// 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(, );
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(, );
this.groupBox4.TabIndex = ;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "操作区";
//
// button3
//
this.button3.Location = new System.Drawing.Point(, );
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(, );
this.button3.TabIndex = ;
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(, );
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(, );
this.groupBox5.TabIndex = ;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "要刷网站地址";
//
// label1
//
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "网站地址";
//
// txtWebUrl
//
this.txtWebUrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtWebUrl.Location = new System.Drawing.Point(, );
this.txtWebUrl.Name = "txtWebUrl";
this.txtWebUrl.Size = new System.Drawing.Size(, );
this.txtWebUrl.TabIndex = ;
this.txtWebUrl.Text = "http://www.51solve.com/";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(, );
this.ClientSize = new System.Drawing.Size(, );
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 = ;
const int INTERNET_OPEN_TYPE_PROXY = ; 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[].Text = "正在使用" + arrText[k].ToString() + "代理IP访问网站";
this.listBox1.SetSelected(k,true);
RefreshIESettings(arrText[k].ToString());
System.Object nullObject = ;
string strTemp = String.Empty;
System.Object nullObjStr = strTemp;
axWebBrowser1.Navigate(strUrl, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
k+=;
if(k>=i)k=;
}
private void button1_Click_1(object sender, System.EventArgs e)
{
arrText.Clear();
i = ;
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+=;
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 == && Total == )return;
if(strUrl.Length == )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 = ;
listBox1.Items.Clear();
string strHtml = "";
string strPort = "";
string strResultIP = "";
long PosB = ;
long PosA = ;
long PosC = ;
string Url = "http://www.pass-e.com/proxy/";
try
{
strHtml = GetHtml(Url);
strHtml = checkStr(strHtml);
strHtml = strHtml.ToLower();
PosA = strHtml.IndexOf("list",);
//MessageBox.Show(GetHtml(Url));
while(PosA>)
{
i+=;
PosB = strHtml.IndexOf(",",(int)PosA);
strResultIP = strHtml.Substring((int)PosA,(int)PosB-(int)PosA);
strResultIP = strResultIP.Replace("list","");
PosC = strHtml.IndexOf(",",(int)PosB+);
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)); 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(" " ,"");
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那么你的网站流量变飞速的提升。
c#换ip代理源码的更多相关文章
- java 1.8 动态代理源码分析
JDK8动态代理源码分析 动态代理的基本使用就不详细介绍了: 例子: class proxyed implements pro{ @Override public void text() { Syst ...
- java动态代理源码解析
众所周知,java动态代理同反射原理一直是许多框架的底层实现,之前一直没有时间来分析动态代理的底层源码,现结合源码分析一下动态代理的底层实现 类和接口 java动态代理的主要类和接口有:java.la ...
- 动态代理学习(二)JDK动态代理源码分析
上篇文章我们学习了如何自己实现一个动态代理,这篇文章我们从源码角度来分析下JDK的动态代理 先看一个Demo: public class MyInvocationHandler implements ...
- JDK动态代理源码学习
继上一篇博客设计模式之代理模式学习之后http://blog.csdn.net/u014427391/article/details/75115928,本博客介绍JDK动态代理的实现原理,学习一下JD ...
- jdk 动态代理源码分析
闲来无事,撸撸源码 使用方法 直接看代码吧.. package com.test.demo.proxy; import java.lang.reflect.InvocationHandler; imp ...
- JDK7动态代理源码分析
IObject proxy = (IObject) Proxy.newProxyInstance(IObject.class.getClassLoader(), new Class[]{IObject ...
- JDK动态代理源码解析
动态代理.静态代理优缺点 关于JDK的动态代理,最为人熟知的可能要数Spring AOP的实现,默认情况下,Spring AOP的实现对于接口来说就是使用的JDK的动态代理来实现的,而对于类的 ...
- JDK动态代理源码分析
先抛出一个问题,JDK的动态代理为什么不支持对实现类的代理,只支持接口的代理??? 首先来看一下如何使用JDK动态代理.JDK提供了Java.lang.reflect.Proxy类来实现动态代理的,可 ...
- 深入剖析JDK动态代理源码实现
动态代理.静态代理优缺点优点:业务类只需要关注业务逻辑本身,保证了业务类的重用性.这是代理的共有优点.动态代理只有在用到被代理对象的时候才会对被代理类进行类加载. 而静态代理在编译器就已经开始占内存了 ...
随机推荐
- Leetcode#90 Subsets II
原题地址 跟Subsets(参见这篇文章)类似. 但因为有重复元素,所以要考虑去重问题. 什么情况下会出现重复呢?比如S = {5, 5, 5},如果要选1个5,一共有C(3,1)=3种选法,即100 ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- DSP中常用的C语言关键字
const Ø使用:const 数据类型 变量名: Ø作用:优化存储器的分配,表示变量的内容是常数,不会改变. Ø举例:const char tab[1024]={显示数据}; volatile(易变 ...
- uialertview 改变文字显示位置
- (void)willPresentAlertView:(UIAlertView *)alertView{ UIView * view = [alertView.subviews objectAtI ...
- HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript
HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript Though it's not ...
- 疯狂java讲义——多态
父类 f = new 子类(); 引用变量f,在编译时类型是父类,在运行时类型是子类类型.当这个引用变量调用子类重写父类的那个方法的时候,实际执行的是子类中重写后的那个方法.当运行的时候调用该变量的方 ...
- hadoop安装问题
1. 运行start-dfs.sh启动HDFS守护进程,start-yarn.sh面向YARN的资源器和节点管理器,资源管理器web地址是http://localhost:8080/.输入stop.d ...
- ACE 1.1.9 发布,开源云端代码编辑器
点这里 ACE 1.1.9 发布,开源云端代码编辑器 oschina 发布于: 2015年04月06日 (1评) 分享到: 收藏 +25 4月18日 武汉 源创会开始报名,送华为开发板 ACE ...
- SQL技术内幕-8 使用WITH AS提高性能简化嵌套SQL
--本文来源:http://www.cnblogs.com/fygh/archive/2011/08/31/2160266.html 一.WITH AS的含义 WITH AS短语,也叫做子查询部分(s ...
- java集合之ArrayList的实现原理
1. ArrayList概述: ArrayList是List接口的可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类还提供一些方法来操作内部 ...