国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

http代理測試

2019-11-14 13:36:47
字體:
來源:轉載
供稿:網友
Technorati 標記: http 代理驗證及測試
Technorati 標記: C#

參考了網上很多資料,綜合整理出來最終的代碼:

 
using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.GC; using static System.Net.WebRequest;namespace 代理測試 {     class PRogram     {         int printCount;         Uri uri;         Encoding bin;         string[] ipSectionSpan = { "10.197.255.", "10.197.198." };         NetworkCredential credit;        [STAThread]         static void Main(string[] args)         {             new Program();             ReadKey();         }        public Program()         {             var dr = new AppSettingsReader();            credit = new NetworkCredential(                 dr.GetValue("uid", typeof(string)).ToString(),                 dr.GetValue("pwd", typeof(string)).ToString());            //var creadentiCache = new CredentialCache();             uri = new Uri("http://wwww.baidu.com/");            bin = Encoding.GetEncoding("UTF-8");            //測試 IpSectionSpan 中所有IP段中所有IP             TestIPSetions();         }        private void TestIPSetions()         {             //for (int i = 1; i < 255; i++)             //{                 TestInSpan(198.ToString());             //}         }        private void TestInSpan(string ipSect)         {             for (var i = 255; i > 0; i--)             {                 var wproxy = new WebProxy(@"10.137." + ipSect + "." + i, 3128);                 //uri = new Uri("http://10.137.255." + i+":3128/");                 //creadentiCache.Add(uri, "Basic", credit);                 //wproxy.Credentials = creadentiCache;                 wproxy.Credentials = credit;                //Collect();                 var req = Create(uri) as HttpWebRequest;                 req.PreAuthenticate = true;                 req.Timeout = 1000; //超時                 req.Proxy = wproxy;                 req.KeepAlive = false;                try                 {                     WebResponse resp;                    req.BeginGetResponse(ra =>                     {                         try                         {                             using (resp = req.EndGetResponse(ra))                             {                                 if (resp != null)                                 {                                     var sr = new StreamReader(resp.GetResponseStream(), bin);                                     var str = sr.ReadToEnd();                                     if (!str.Contains("百度")) return;                                     WriteLine("{0}/t:{1} /t 驗證成功!", printCount++, wproxy.Address);                                     sr.Close();                                     sr.Dispose();                                 }                             }                         }                         catch (Exception ex)                         {                             WriteLine("{0}/t:{1} /t 驗證失敗,失敗原因:/t {2}", printCount++, wproxy.Address, ex.Message);                         }                    }, null);                 }                 catch (Exception e)                 {                     WriteLine(e.Message);                 }             }         }     } } 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 开化县| 五大连池市| 新和县| 巍山| 建始县| 阿鲁科尔沁旗| 紫金县| 尉犁县| 杂多县| 大名县| 赤城县| 通州市| 建瓯市| 云和县| 镇赉县| 阿鲁科尔沁旗| 盱眙县| 嘉义市| 方城县| 静乐县| 稻城县| 泉州市| 宝鸡市| 卓资县| 桂阳县| 吉木萨尔县| 阿坝县| 承德市| 文山县| 黔西| 梅河口市| 区。| 额济纳旗| 香港| 洪洞县| 田林县| 武邑县| 宁德市| 郸城县| 玛多县| 双江|