c#使用socks5(通过curl)

时间:2017-08-09 17:50:42 阅读:695次
c#使用socks5(通过curl)

libcurlnet-1_3.zip下载


using SeasideResearch.LibCurlNet;

public void GetResultBySocks5(string url, String[] args)
{
            this.stringBuffer = new StringBuilder("");
            try
            {
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
                Easy easy = new Easy();
                Easy.WriteFunction wf = new Easy.WriteFunction(this.OnWriteData);
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                easy.SetOpt(CURLoption.CURLOPT_URL, url); //设置访问连接
                easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_SOCKS5);
                easy.SetOpt(CURLoption.CURLOPT_PROXY, this._ip);
                easy.SetOpt(CURLoption.CURLOPT_PROXYPORT, "1080");
                easy.SetOpt(CURLoption.CURLOPT_PROXYUSERPWD, this._username + ":" + this._password);
                easy.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, 20*1000);
                easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, 20*1000);
                if(url.LastIndexOf("ttps://")>0)
                {
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, false);
                }
                easy.Perform();
                easy.Cleanup();
                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                this.StatusTextBox.AppendText(ex.ToString());
            }
            finally
            {
            }
}

public Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
            this.stringBuffer.Append(System.Text.Encoding.UTF8.GetString(buf));
            return size * nmemb;
}


扫描二维码关注程序员爱笔记,接收更多资讯

评论

快速评论