How to test if a proxy server is working or not?

前端 未结 4 1923
长情又很酷
长情又很酷 2020-12-31 09:38

I\'ve got a pretty big list with proxy servers and their corresponding ports. How can I check, if they are working or not?

4条回答
  •  盖世英雄少女心
    2020-12-31 10:22

    try this:

    public static bool SoketConnect(string host, int port)
    {
        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);
            if (connsock.Connected)
            {
                is_success = true;
            }
            connsock.Close();
        }
        catch (Exception)
        {
            is_success = false;
        }
        return is_success;
    }
    

提交回复
热议问题