转载

工具篇: 批量快速检测IP

如果有一大堆代理IP地址需要快速检测是否可用如何检测?

肯定会想到多线程并发检测,那么怎么并发检测那?

先上一个最简单的办法:

private bool VerIP(string ip, int port)
{
try
{
HttpWebRequest Req;
HttpWebResponse Resp;
WebProxy proxyObject = new WebProxy(ip, port);// port为端口号 整数型
Req = WebRequest.Create("https://www.baidu.com") as HttpWebRequest;
Req.Proxy = proxyObject; //设置代理
Req.Timeout = 1000; //超时
Resp = (HttpWebResponse)Req.GetResponse();
Encoding bin = Encoding.GetEncoding("UTF-8");
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), bin))
{
string str = sr.ReadToEnd();
if (str.Contains("百度"))
{
Resp.Close();
return true;
}
else
{
return false;
}
}

        }
        catch (Exception ex)
        {
            return false;
        }
    }
正文到此结束
本文目录