Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Parallel Proxy Tester

Still needs work!


Sources





So I just threw together a quick proxy tester that works but it could work better.

The proxy tester only supports HTTP/HTTPS proxies as far as I know, if otherwise please correct me.

In a hurry so I wanted to make this post quick, might come back and update this


Source: https://github.com/Wolfijiyn/SimpleParal...Program.cs
Source Clean (Not tested): https://github.com/Wolfijiyn/SimpleParal...eanCode.cs
Why would you run the loop in it's own thread? It's a Console Application, it won't freeze up. Also, you are not validating inputs, so if someone enters incorrect proxy strings the program crashes. And the Export function is useless, as you can do File.WriteAllText or File.WriteAllLines. And instead of Convert.ToInt32 I suggest you use "int.TryParse(string input, out int output)" as you get a bool returned whether or not the parsing was successful (this adds to the input validation bit). And instead of the if-statement on line 77 you could do this: "return Content.Contains("CmyIP.org");" to shorten it.

These are all minor things, and I don't mean to degrade you or your work as I love the release and effort you put up. This is meant for you to learn from.

PS: If you want, you can use sockets instead of the HttpClient to connect to the proxy server and check if it uses the protocol you want. This method is a bit harder but faster.

EDIT: This was for the first link. In the clean version you already fixed some of the issues I addressed, but not all of them.
(Dec 23, 2017 10:56 AM)Ninja Wrote:  Why would you run the loop in it's own thread? It's a Console Application, it won't freeze up. Also, you are not validating inputs, so if someone enters incorrect proxy strings the program crashes. And the Export function is useless, as you can do File.WriteAllText or File.WriteAllLines. And instead of Convert.ToInt32 I suggest you use "int.TryParse(string input, out int output)" as you get a bool returned whether or not the parsing was successful (this adds to the input validation bit). And instead of the if-statement on line 77 you could do this: "return Content.Contains("CmyIP.org");" to shorten it.

These are all minor things, and I don't mean to degrade you or your work as I love the release and effort you put up. This is meant for you to learn from.

PS: If you want, you can use sockets instead of the HttpClient to connect to the proxy server and check if it uses the protocol you want. This method is a bit harder but faster.

EDIT: This was for the first link. In the clean version you already fixed some of the issues I addressed, but not all of them.

I appriciate the feedback, and I mainly created this as a quick and dirty solution to test my proxies becase I was looking for HTTP/HTTPS proxies specifically.
I'll rewrite the code later and I'll take your comment into consideration! 🤝
(Dec 23, 2017 10:56 AM)Ninja Wrote:  Why would you run the loop in it's own thread? It's a Console Application, it won't freeze up. Also, you are not validating inputs, so if someone enters incorrect proxy strings the program crashes. And the Export function is useless, as you can do File.WriteAllText or File.WriteAllLines. And instead of Convert.ToInt32 I suggest you use "int.TryParse(string input, out int output)" as you get a bool returned whether or not the parsing was successful (this adds to the input validation bit). And instead of the if-statement on line 77 you could do this: "return Content.Contains("CmyIP.org");" to shorten it.

These are all minor things, and I don't mean to degrade you or your work as I love the release and effort you put up. This is meant for you to learn from.

PS: If you want, you can use sockets instead of the HttpClient to connect to the proxy server and check if it uses the protocol you want. This method is a bit harder but faster.

EDIT: This was for the first link. In the clean version you already fixed some of the issues I addressed, but not all of them.

I absolutely agree with you about usage of sockets is faster...

Here's a quick socket variant for test

Code
public class ProxyList
   {
       public string ProxyIP { get; set; }
       public int ProxyPort { get; set; }

       public ProxyList(string _proxyIP,int _proxyPort)
       {
           ProxyIP = _proxyIP;
           ProxyPort = _proxyPort;
       }
   }

Code
List<ProxyList> proxyList = new List<ProxyList>()
       {
          new ProxyList("193.227.49.83",8080),
          new ProxyList("189.85.29.98",8080),
          new ProxyList("87.226.68.130",2020),
          new ProxyList("109.175.6.194",8080)
         
       };

Code
Parallel.ForEach(proxyList, pl =>
           {
               ProxyTest(pl.ProxyIP,pl.ProxyPort);
           });
Code
private string ProxyTest(string ip,int port)
       {
           try
           {
               Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
               socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 2000);
               var _proxyIP = IPAddress.Parse(ip);
               var _endpoint = new IPEndPoint(_proxyIP, port);
               socket.Connect(_endpoint);
               if (socket.Connected)

                   return $"Proxy {ip}:{port} is ok";
               socket.Close();
               return $"Proxy {ip}:{port} is faild test";

           }
           catch
           {
               return $"Error Proxy {ip}:{port} is faild test";

           }
       }
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
(Dec 23, 2017 07:47 PM)itcorp Wrote:  - LARGE QUOTE -

Great suggestion, though I suggest input validation and more specific error handling so you know the exact reason a proxy doesn't work (incorrect proxy string, IP failed to parse, port out of range, host is down, host timed out, etc.). Also, instead of returning a string, you could return a bool and/or throw exceptions.

To OP:This method is not guaranteed, as that the host is up does not necessarily mean that it acts as a proxy; though the bad part is that you have to send an HTTP request to see if it indeed does act as a proxy. For socks proxies it is different and easier as there is a handshake and authentication protocol.


Here is my attempt (Click to View)

This of course only checks if the host is up. If you want, you can keep open the socket instance and then try a few different protocols on that to identify which type of proxy it is (if it is one in the first place).
(Dec 23, 2017 08:25 PM)Ninja Wrote:  Great suggestion, though I suggest input validation and more specific error handling so you know the exact reason a proxy doesn't work (incorrect proxy string, IP failed to parse, port out of range, host is down, host timed out, etc.). Also, instead of returning a string, you could return a bool and/or throw exceptions.

Again agree with you.I gave this as an example your way is much more elegant and better from my i did not go deeper with this.Thanks for your reply
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
Great job! havent seen projects from you in some times, wasnt active;)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by simmerApr 9, 2022 02:34 PM 5 246 Apr 9, 2022 02:34 PM
Last Post: simmer
[Java] by blackcoder00Apr 30, 2019 05:57 PM 3 202 Apr 30, 2019 05:57 PM
Last Post: Caliban
[C#] by 991z3r0Dec 5, 2018 04:16 AM 4 233 Dec 5, 2018 04:16 AM
Last Post: deepshit