习惯性地打开“代理猎手”,没有一个代理可用,到http://info.hustonline.net/info/index/proxyshow.aspx 找几个试试,失望了~~
还是继续把上次的项目再打开吧~
GetProxy:
今晚试了一下果然真爽!请求http://info.hustonline.net/info/index/proxyshow.aspx终于有结果了
private void btnWork_Click(object sender, EventArgs e)
{
result = "";//要写入txt文档的代理字符串
count = 0;//代理个数
if (tbFile.Text == "" & tbUrl.Text == "")
{
MessageBox.Show("请选择方式!", "空值");
return;
}
else
{
btnWork.Enabled = false;
btnSave.Enabled = false;
if (rbtnUrl.Checked == true)
{
url = tbUrl.Text;
type = "url";
}
else
{
url = tbFile.Text;
type = "dir";
}
//url = "http://www.gaisoft.com/2005/4-6/11470-13.html";
url = "http://info.hustonline.net/index/proxyshow.aspx";//就这个url困扰着好几天,请求其它的都可以为啥这个不行?而且浏览器是可以访问到该地址的
//有说是跟二级域名有关,但像http://msdn1.microsoft.com/en-us/default.aspx
这样的url总可访问得到吧?
//url = "http://www.sina.com";
deleWork work = new deleWork(GetProxy);
work.BeginInvoke(url, new AsyncCallback(AfterWork), null);
}
}
private void GetProxy(string para)
{
if (type == "url")
{
request = (HttpWebRequest)HttpWebRequest.Create(para);
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.Default);
tmp = reader.ReadToEnd();
mchColl = ipRegex.Matches(tmp);
foreach (Match match in mchColl)
{
result += match.ToString() + "\r\n";
}
count = mchColl.Count;
MessageBox.Show("一共找到 " + count.ToString() + " 个代理");
}
else
{
try
{
tmp = File.ReadAllText(tbFile.Text, Encoding.Default);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
mchColl = ipRegex.Matches(tmp);
foreach (Match match in mchColl)
{
result += match.ToString() + "\r\n";
}
count = mchColl.Count;
MessageBox.Show("一共找到 " + count.ToString() + " 个代理");
}
}
private void AfterWork(IAsyncResult result)
{
object[] o = { this, System.EventArgs.Empty };
btnWork.BeginInvoke(new System.EventHandler(UpdateUI), o);
}
private void UpdateUI(object o, System.EventArgs e)
{
btnSave.Enabled = true;
btnWork.Enabled = true;
}
这是”花刺“查找”华中大的代理,只查出9个来:{
result = "";//要写入txt文档的代理字符串
count = 0;//代理个数
if (tbFile.Text == "" & tbUrl.Text == "")
{
MessageBox.Show("请选择方式!", "空值");
return;
}
else
{
btnWork.Enabled = false;
btnSave.Enabled = false;
if (rbtnUrl.Checked == true)
{
url = tbUrl.Text;
type = "url";
}
else
{
url = tbFile.Text;
type = "dir";
}
//url = "http://www.gaisoft.com/2005/4-6/11470-13.html";
url = "http://info.hustonline.net/index/proxyshow.aspx";//就这个url困扰着好几天,请求其它的都可以为啥这个不行?而且浏览器是可以访问到该地址的
//有说是跟二级域名有关,但像http://msdn1.microsoft.com/en-us/default.aspx
这样的url总可访问得到吧?
//url = "http://www.sina.com";
deleWork work = new deleWork(GetProxy);
work.BeginInvoke(url, new AsyncCallback(AfterWork), null);
}
}
private void GetProxy(string para)
{
if (type == "url")
{
request = (HttpWebRequest)HttpWebRequest.Create(para);
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.Default);
tmp = reader.ReadToEnd();
mchColl = ipRegex.Matches(tmp);
foreach (Match match in mchColl)
{
result += match.ToString() + "\r\n";
}
count = mchColl.Count;
MessageBox.Show("一共找到 " + count.ToString() + " 个代理");
}
else
{
try
{
tmp = File.ReadAllText(tbFile.Text, Encoding.Default);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
mchColl = ipRegex.Matches(tmp);
foreach (Match match in mchColl)
{
result += match.ToString() + "\r\n";
}
count = mchColl.Count;
MessageBox.Show("一共找到 " + count.ToString() + " 个代理");
}
}
private void AfterWork(IAsyncResult result)
{
object[] o = { this, System.EventArgs.Empty };
btnWork.BeginInvoke(new System.EventHandler(UpdateUI), o);
}
private void UpdateUI(object o, System.EventArgs e)
{
btnSave.Enabled = true;
btnWork.Enabled = true;
}

再多加点吧:

还有可以从文件检索代理:

把结果保存为 txt 文件,之后的工作就由“花刺”来搞定了~~