Http proxy test, http Proxy

Source: Internet
Author: User

Http proxy test, http Proxy
Technorati flag: http Proxy verification and testing Technorati flag: C #

Based on a lot of information on the Internet, the final code is summarized as follows:

 
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 proxy test {class Program {in T 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 = n Ew CredentialCache (); uri = new Uri ("http://wwww.baidu.com/"); bin = Encoding. getEncoding ("UTF-8"); // test all 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; // 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! ", PrintCount ++, wproxy. address); sr. close (); sr. dispose () ;}} catch (Exception ex) {WriteLine ("{0} \ t: {1} \ t Verification Failed, cause of failure: \ t {2 }", printCount ++, wproxy. address, ex. message) ;}}, null) ;}catch (Exception e) {WriteLine (e. message );}}}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.