1 很多朋友都想如何提高自己的网站流量,可是都没有什么好的办法
2 经过很长时间的研究,在C#中实现了,当然了,这部分代码其中一部分是网上的,不是原创。
3
4 using System;
5 using System.Drawing;
6 using System.Collections;
7 using System.ComponentModel;
8 using System.Windows.Forms;
9 using System.Data;
10 using System.Runtime.InteropServices;
11 using System.Diagnostics;
12 using System.IO;
13 using System.Text.RegularExpressions;
14 using System.Text;
15 using System.Net;
16 namespace WebSock
17 {
18 /// <summary>
19 /// Form1 的摘要说明。
20 /// </summary>
21 public class Form1 : System.Windows.Forms.Form
22 {
23 private System.Windows.Forms.GroupBox groupBox1;
24 private AxSHDocVw.AxWebBrowser axWebBrowser1;
25 private System.Windows.Forms.Button button1;
26 private System.Windows.Forms.Button button2;
27 private System.Windows.Forms.OpenFileDialog openFileDialog1;
28 private System.Windows.Forms.Timer timer1;
29 private System.ComponentModel.IContainer components;
30 private System.Windows.Forms.StatusBar statusBar1;
31 private System.Windows.Forms.StatusBarPanel statusBarPanel1;
32 private System.Windows.Forms.GroupBox groupBox2;
33 private System.Windows.Forms.GroupBox groupBox3;
34 private System.Windows.Forms.GroupBox groupBox4;
35 private System.Windows.Forms.Button button3;
36 ArrayList arrText = new ArrayList();
37 int Total = 0;
38 int i,k=0;
39 private System.Windows.Forms.GroupBox groupBox5;
40 private System.Windows.Forms.Label label1;
41 private System.Windows.Forms.TextBox txtWebUrl;
42 private const string TitleInfo = "程序制作红色银狐";
43 private System.Windows.Forms.ListBox listBox1;
44 private string strUrl = "";
45 public Form1()
46 {
47 //
48 // Windows 窗体设计器支持所必需的
49 //
50 InitializeComponent();
51 //
52 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
53 //
54 }
55
56 /// <summary>
57 /// 清理所有正在使用的资源。
58 /// </summary>
59 protected override void Dispose( bool disposing )
60 {
61 if( disposing )
62 {
63 if (components != null)
64 {
65 components.Dispose();
66 }
67 }
68 base.Dispose( disposing );
69 }
70
71 #region Windows 窗体设计器生成的代码
72 /// <summary>
73 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
74 /// 此方法的内容。
75 /// </summary>
76 private void InitializeComponent()
77 {
78 this.components = new System.ComponentModel.Container();
79 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
80 this.groupBox1 = new System.Windows.Forms.GroupBox();
81 this.groupBox3 = new System.Windows.Forms.GroupBox();
82 this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
83 this.groupBox2 = new System.Windows.Forms.GroupBox();
84 this.listBox1 = new System.Windows.Forms.ListBox();
85 this.button1 = new System.Windows.Forms.Button();
86 this.button2 = new System.Windows.Forms.Button();
87 this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
88 this.timer1 = new System.Windows.Forms.Timer(this.components);
89 this.statusBar1 = new System.Windows.Forms.StatusBar();
90 this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
91 this.groupBox4 = new System.Windows.Forms.GroupBox();
92 this.button3 = new System.Windows.Forms.Button();
93 this.groupBox5 = new System.Windows.Forms.GroupBox();
94 this.label1 = new System.Windows.Forms.Label();
95 this.txtWebUrl = new System.Windows.Forms.TextBox();
96 this.groupBox1.SuspendLayout();
97 this.groupBox3.SuspendLayout();
98 ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
99 this.groupBox2.SuspendLayout();
100 ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
101 this.groupBox4.SuspendLayout();
102 this.groupBox5.SuspendLayout();
103 this.SuspendLayout();
104 //
105 // groupBox1
106 //
107 this.groupBox1.Controls.Add(this.groupBox3);
108 this.groupBox1.Controls.Add(this.groupBox2);
109 this.groupBox1.Location = new System.Drawing.Point(0, 0);
110 this.groupBox1.Name = "groupBox1";
111 this.groupBox1.Size = new System.Drawing.Size(810, 440);
112 this.groupBox1.TabIndex = 0;
113 this.groupBox1.TabStop = false;
114 //
115 // groupBox3
116 //
117 this.groupBox3.Controls.Add(this.axWebBrowser1);
118 this.groupBox3.Location = new System.Drawing.Point(312, 8);
119 this.groupBox3.Name = "groupBox3";
120 this.groupBox3.Size = new System.Drawing.Size(490, 424);
121 this.groupBox3.TabIndex = 2;
122 this.groupBox3.TabStop = false;
123 this.groupBox3.Text = "浏览器";
124 //
125 // axWebBrowser1
126 //
127 this.axWebBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
128 | System.Windows.Forms.AnchorStyles.Left)
129 | System.Windows.Forms.AnchorStyles.Right)));
130 this.axWebBrowser1.ContainingControl = this;
131 this.axWebBrowser1.Enabled = true;
132 this.axWebBrowser1.Location = new System.Drawing.Point(8, 16);
133 this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
134 this.axWebBrowser1.Size = new System.Drawing.Size(474, 400);
135 this.axWebBrowser1.TabIndex = 0;
136 //
137 // groupBox2
138 //
139 this.groupBox2.Controls.Add(this.listBox1);
140 this.groupBox2.Location = new System.Drawing.Point(8, 8);
141 this.groupBox2.Name = "groupBox2";
142 this.groupBox2.Size = new System.Drawing.Size(296, 424);
143 this.groupBox2.TabIndex = 1;
144 this.groupBox2.TabStop = false;
145 this.groupBox2.Text = "代理IP地址";
146 //
147 // listBox1
148 //
149 this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
150 this.listBox1.ItemHeight = 12;
151 this.listBox1.Location = new System.Drawing.Point(8, 16);
152 this.listBox1.Name = "listBox1";
153 this.listBox1.Size = new System.Drawing.Size(280, 398);
154 this.listBox1.TabIndex = 2;
155 //
156 // button1
157 //
158 this.button1.Location = new System.Drawing.Point(310, 16);
159 this.button1.Name = "button1";
160 this.button1.Size = new System.Drawing.Size(176, 32);
161 this.button1.TabIndex = 1;
162 this.button1.Text = "载入代理IP";
163 this.button1.Click += new System.EventHandler(this.button1_Click_1);
164 //
165 // button2
166 //
167 this.button2.Location = new System.Drawing.Point(486, 16);
168 this.button2.Name = "button2";
169 this.button2.Size = new System.Drawing.Size(176, 32);
170 this.button2.TabIndex = 2;
171 this.button2.Text = "开始刷流量";
172 this.button2.Click += new System.EventHandler(this.button2_Click);
173 //
174 // timer1
175 //
176 this.timer1.Interval = 10000;
177 this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
178 //
179 // statusBar1
180 //
181 this.statusBar1.Dock = System.Windows.Forms.DockStyle.None;
182 this.statusBar1.Location = new System.Drawing.Point(0, 552);
183 this.statusBar1.Name = "statusBar1";
184 this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
185 this.statusBarPanel1});
186 this.statusBar1.ShowPanels = true;
187 this.statusBar1.Size = new System.Drawing.Size(810, 24);
188 this.statusBar1.TabIndex = 3;
189 //
190 // statusBarPanel1
191 //
192 this.statusBarPanel1.Width = 820;
193 //
194 // groupBox4
195 //
196 this.groupBox4.Controls.Add(this.button3);
197 this.groupBox4.Controls.Add(this.button2);
198 this.groupBox4.Controls.Add(this.button1);
199 this.groupBox4.Location = new System.Drawing.Point(0, 496);
200 this.groupBox4.Name = "groupBox4";
201 this.groupBox4.Size = new System.Drawing.Size(810, 56);
202 this.groupBox4.TabIndex = 4;
203 this.groupBox4.TabStop = false;
204 this.groupBox4.Text = "操作区";
205 //
206 // button3
207 //
208 this.button3.Location = new System.Drawing.Point(134, 16);
209 this.button3.Name = "button3";
210 this.button3.Size = new System.Drawing.Size(176, 32);
211 this.button3.TabIndex = 3;
212 this.button3.Text = "从网络获取代理IP";
213 this.button3.Click += new System.EventHandler(this.button3_Click);
214 //
215 // groupBox5
216 //
217 this.groupBox5.Controls.Add(this.label1);
218 this.groupBox5.Controls.Add(this.txtWebUrl);
219 this.groupBox5.Location = new System.Drawing.Point(0, 444);
220 this.groupBox5.Name = "groupBox5";
221 this.groupBox5.Size = new System.Drawing.Size(810, 48);
222 this.groupBox5.TabIndex = 5;
223 this.groupBox5.TabStop = false;
224 this.groupBox5.Text = "要刷网站地址";
225 //
226 // label1
227 //
228 this.label1.Location = new System.Drawing.Point(16, 21);
229 this.label1.Name = "label1";
230 this.label1.Size = new System.Drawing.Size(56, 16);
231 this.label1.TabIndex = 1;
232 this.label1.Text = "网站地址";
233 //
234 // txtWebUrl
235 //
236 this.txtWebUrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
237 this.txtWebUrl.Location = new System.Drawing.Point(80, 16);
238 this.txtWebUrl.Name = "txtWebUrl";
239 this.txtWebUrl.Size = new System.Drawing.Size(720, 21);
240 this.txtWebUrl.TabIndex = 0;
241 this.txtWebUrl.Text = "http://www.51solve.com/";
242 //
243 // Form1
244 //
245 this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
246 this.ClientSize = new System.Drawing.Size(810, 575);
247 this.Controls.Add(this.groupBox5);
248 this.Controls.Add(this.groupBox4);
249 this.Controls.Add(this.statusBar1);
250 this.Controls.Add(this.groupBox1);
251 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
252 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
253 this.MaximizeBox = false;
254 this.Name = "Form1";
255 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
256 this.Text = "网站流量访问程序制作:红色银狐";
257 this.groupBox1.ResumeLayout(false);
258 this.groupBox3.ResumeLayout(false);
259 ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
260 this.groupBox2.ResumeLayout(false);
261 ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
262 this.groupBox4.ResumeLayout(false);
263 this.groupBox5.ResumeLayout(false);
264 this.ResumeLayout(false);
265
266 }
267 #endregion
268
269 /// <summary>
270 /// 应用程序的主入口点。
271 /// </summary>
272 [STAThread]
273 static void Main()
274 {
275 Application.Run(new Form1());
276 }
277 //定义结构体代理信息
278 public struct Struct_INTERNET_PROXY_INFO
279 {
280 public int dwAccessType;
281 public IntPtr proxy;
282 public IntPtr proxyBypass;
283 };
284 [DllImport("wininet.dll", SetLastError = true)]
285 private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
286
287 private void RefreshIESettings(string strProxy)
288 {
289 const int INTERNET_OPTION_PROXY = 38;
290 const int INTERNET_OPEN_TYPE_PROXY = 3;
291
292 Struct_INTERNET_PROXY_INFO struct_IPI;
293
294 // Filling in structure
295 struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
296 struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
297 struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
298
299 // Allocating memory
300 IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
301
302 // Converting structure to IntPtr
303 Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
304
305 bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
306 }
307
308 private void StartShua()
309 {
310 statusBar1.Panels[0].Text = "正在使用" + arrText[k].ToString() + "代理IP访问网站";
311 this.listBox1.SetSelected(k,true);
312 RefreshIESettings(arrText[k].ToString());
313 System.Object nullObject = 0;
314 string strTemp = String.Empty;
315 System.Object nullObjStr = strTemp;
316 axWebBrowser1.Navigate(strUrl, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
317 k+=1;
318 if(k>=i)k=0;
319 }
320 private void button1_Click_1(object sender, System.EventArgs e)
321 {
322 arrText.Clear();
323 i = 0;
324 if(openFileDialog1.ShowDialog() ==DialogResult.OK)
325 {
326 string strPath,strLine = "";
327 strPath = openFileDialog1.FileName.ToString();
328 StreamReader sr = new StreamReader(strPath);
329 while(strLine != null)
330 {
331 strLine = sr.ReadLine();
332 if(strLine != null)
333 {
334 i+=1;
335 arrText.Add(strLine);
336 listBox1.Items.Add(strLine);
337 }
338 }
339 sr.Close();
340 }
341 }
342 private void timer1_Tick(object sender, System.EventArgs e)
343 {
344 StartShua();
345 }
346
347 private void button2_Click(object sender, System.EventArgs e)
348 {
349 Total = listBox1.Items.Count;
350 strUrl = txtWebUrl.Text;
351 if(button2.Text == "开始刷流量")
352 {
353 if(i == 0 && Total == 0)return;
354 if(strUrl.Length == 0)return;
355 StartShua();
356 button2.Text = "停止刷流量";
357 timer1.Enabled = true;
358 timer1.Start();
359 button1.Enabled = false;
360 button3.Enabled = false;
361 }
362 else
363 {
364 timer1.Stop();
365 timer1.Enabled = false;
366 button2.Text = "开始刷流量";
367 button1.Enabled = true;
368 button3.Enabled = true;
369 arrText.Clear();
370 }
371 }
372
373 private void button3_Click(object sender, System.EventArgs e)
374 {
375 arrText.Clear();
376 i = 0;
377 listBox1.Items.Clear();
378 string strHtml = "";
379 string strPort = "";
380 string strResultIP = "";
381 long PosB = 0;
382 long PosA = 0;
383 long PosC = 0;
384 string Url = "http://www.pass-e.com/proxy/";
385 try
386 {
387 strHtml = GetHtml(Url);
388 strHtml = checkStr(strHtml);
389 strHtml = strHtml.ToLower();
390 PosA = strHtml.IndexOf("list",0);
391 //MessageBox.Show(GetHtml(Url));
392 while(PosA>0)
393 {
394 i+=1;
395 PosB = strHtml.IndexOf(",",(int)PosA);
396 strResultIP = strHtml.Substring((int)PosA,(int)PosB-(int)PosA);
397 strResultIP = strResultIP.Replace("list","");
398 PosC = strHtml.IndexOf(",",(int)PosB+1);
399 strPort = strHtml.Substring((int)PosB,(int)PosC-(int)PosB);
400 strPort = strPort.Replace(",","");
401 listBox1.Items.Add(strResultIP+":"+strPort);
402 PosA = strHtml.IndexOf("list",(int)PosC);
403 arrText.Add(strResultIP+":"+strPort);
404 }
405 }
406 catch(Exception ex)
407 {
408 MessageBox.Show(ex.Message,TitleInfo,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
409 }
410 }
411 public string checkStr(string html)
412 {
413 string str = Convert.ToString((char)34);
414
415 Regex regex1 = new Regex(@"<mce:script[/s/S]+</script *><!--
416 ", RegexOptions.IgnoreCase);
417 Regex regex2 = new Regex(@" href *= *[/s/S]*script *:", RegexOptions.IgnoreCase);
418 Regex regex3 = new Regex(@" no[/s/S]*=", RegexOptions.IgnoreCase);
419 Regex regex4 = new Regex(@"<iframe[/s/S]+</iframe *>", RegexOptions.IgnoreCase);
420 Regex regex5 = new Regex(@"<frameset[/s/S]+</frameset *>", RegexOptions.IgnoreCase);
421 Regex regex6 = new Regex(@"/<img[^/>]+/>", RegexOptions.IgnoreCase);
422 Regex regex7 = new Regex(@"</p>", RegexOptions.IgnoreCase);
423 Regex regex8 = new Regex(@"<p>", RegexOptions.IgnoreCase);
424 Regex regex9 = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);
425 html = html.Replace("/r/n","");
426 //html = regex1.Replace(html, ""); //过滤<script>
427 // --></mce:script>标记
428 html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
429 html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
430 html = regex4.Replace(html, ""); //过滤iframe
431 html = regex5.Replace(html, ""); //过滤frameset
432 html = regex6.Replace(html, ""); //过滤frameset
433 html = regex7.Replace(html, ""); //过滤frameset
434 html = regex8.Replace(html, ""); //过滤frameset
435 html = regex9.Replace(html, "");
436 html = html.Replace(" ", "");
437 html = html.Replace("</strong>", "");
438 html = html.Replace("<strong>", "");
439 html = html.Replace("/n","");
440 html = html.Replace(str ,"");
441 html = html.Replace("}" ,"");
442 html = html.Replace("(" ,"");
443 html = html.Replace(")" ,"");
444 //html = html.Replace(";" ,"");
445 html = html.Replace("'" ,"");
446 html = html.Replace(" " ,"");
447 html = html.Replace(" ","");
448 return html;
449 }
450 public string GetHtml(string myUrl)
451 {
452 HttpWebRequest myHttpWebRequest;
453
454 HttpWebResponse myHttpWebResponse;
455
456 //string Html;
457
458 try
459 {
460
461 string URL = myUrl;
462
463 Uri myUri = new Uri(myUrl);
464
465 WebRequest myWebRequest = WebRequest.Create(URL);
466
467 //使用Creat方法创建WebRequest实例
468
469 myHttpWebRequest = (HttpWebRequest)myWebRequest;
470
471 //实现WebRequest类型和HttpWebRequest类型的转换
472
473 WebResponse myWebResponse = myHttpWebRequest.GetResponse();
474
475 //获得响应信息
476
477 myHttpWebResponse = (HttpWebResponse)myWebResponse;
478
479 Stream myStream = myHttpWebResponse.GetResponseStream();
480
481 //获得从当前Internet资源返回的响应流数据
482
483 StreamReader srReader = new StreamReader(myStream, Encoding.Default);
484
485 //利用获得的响应流和系统缺省编码来初始化StreamReader实例。
486
487 string sTemp = srReader.ReadToEnd();
488
489 //从响应流从读取数据
490
491 srReader.Close();
492
493 return sTemp;
494 }
495
496 //显示读取的数据 ( )
497
498 catch (WebException WebExcp)
499 {
500
501 return WebExcp.Message.ToString();
502 }
503 }
504 }
505
506 }
507
508
509
510
511
512 通过它的实现,只要你有足够的代理IP那么你的网站流量变飞速的提升。