弹来弹去跑马灯!

test lumer video

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Threading.Tasks;
namespace CheckProxy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List list = new List();
private void button1_Click(object sender, EventArgs e)
{
List taskList = new List();
for (int i = 0; i < list.Count-1; i++) {
// Task.Factory.StartNew(() => testProxy(list[i], i));
testProxy(list[i], i);
}
}
void testProxy(Proxy proxy,int i)
{
try
{
WebProxy p = new WebProxy(proxy.ip, proxy.port);
HttpWebRequest Req = (HttpWebRequest)HttpWebRequest.Create("http://www.baidu.com");
Req.Method = "Head";
Req.Proxy = p;
Req.Timeout = 5000;
WebResponse respnse= Req.GetResponse();
//Text = "" + respnse.ContentLength;
Invoke(new Action(() =>
{
listView1.Items[i].SubItems[2].Text = " OK";
}));
}
catch(Exception ex) {
// MessageBox.Show(ex.Message );
Invoke(new Action(() =>
{
listView1.Items[i].SubItems[2].Text = " bad";
}));
}
Application.DoEvents();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
HttpWebRequest Req = (HttpWebRequest)HttpWebRequest.Create("http://api.xicidaili.com/free2016.txt");view-source:http://www.kuaidaili.com/free/inha/
WebResponse respnse = Req.GetResponse();
Stream stream= respnse.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string strList= reader.ReadToEnd();
reader.Close();
stream.Close();
reader = null;
stream = null;
foreach(string s in strList.Split("\n".ToArray())){
if (s.Trim() == "") continue;
ListViewItem item= new ListViewItem(){ Text=""+s.Split(':')[0]};
item.SubItems.Add(""+s.Split(':')[1]);
item.SubItems.Add("");
listView1.Items.Add(item);
list.Add(new Proxy() { ip = s.Split(':')[0], port = int.Parse(s.Split(':')[1])});
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
public class Proxy{
public string ip {get;set;}
public int port {get;set;}
}
}
posted @ 2017-10-11 14:51  wgscd  阅读(128)  评论(0)    收藏  举报