C# Test if proxies are working before using them
<p>I want to check if the the proxies in my list are working before using them, is it possible?</p>

<p>It's easy for HTTP/HTTPS since you only have to use the webclient but for socks?</p>

<p>I tough this could work for all </p>

<pre><code>public static bool SoketConnect(string addresse)
    {
        string[] proxy = addresse.Split(':');
        if (proxy.Count() == 2)
        {
            string host = proxy[0];
            int port = Convert.ToInt32(proxy[1]);

            var is_success = false;
            try
            {
                var connsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                connsock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 200);
                System.Threading.Thread.Sleep(500);
                var hip = IPAddress.Parse(host);
                var ipep = new IPEndPoint(hip, port);
                connsock.Connect(ipep);
                    try
                    {
                        byte[] outStream = System.Text.Encoding.ASCII.GetBytes("ping");
                        byte[] inStream = new byte[100];
                        connsock.Send(outStream);
                        connsock.ReceiveTimeout = 500;
                        connsock.Receive(inStream);
                        string message = System.Text.Encoding.ASCII.GetString(inStream);
                        foreach (var bytes in inStream)
                        {
                            if (bytes != 0)
                            {
                                is_success = true;
                                break;
                            }
                        }
                        connsock.Disconnect(false);
                    }
                    catch(Exception ex)
                    {
                        is_success = false;
                    }
                connsock.Close();
            }
            catch (Exception ex)
            {
                is_success = false;
            }
            return is_success;
        }
        else
            return false;
    }
</code></pre>

<p>but i always get the exception </p>

<blockquote>
  <p>"The underlying connection was closed: The connection was closed
  unexpectedly." System.Net.WebException</p>
</blockquote>

<p>tldr; How to check if my socks proxies are working ( Which comes back to how to use a socks proxy)</p>

<p>EDIT: still doesn't help,need an answer
EDIT2 : Only pinging the proxy isn't the right thing to do</p>