Technorati Tags: http proxy authentication and test Technorati tags: 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 Agent Test {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"); Test all IP testipsetions () in all IP segments in the Ipsectionspan; 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; Timeout 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 ("Baidu")) return; WriteLine ("{0}\t:{1} \ t verified success! ", printcount++, Wproxy. Address); Sr. Close (); Sr. Dispose (); }}} catch (Exception ex) { WriteLine ("{0}\t:{1} \ t authentication failed, reason for failure: \ t {2}", printcount++, Wproxy. Address, ex. Message); }}, NULL); } catch (Exception e) {WriteLine (e.message); } } } } }
HTTP proxy Test