I wanted to buy a huge list of proxies that I have because I'm only interested in those who use the https (SSL) protocol and those that are not in China. Looking for a quick way to do it I found this function.
string proxyWorks(string ip, int port, string proxytype="")
{
CURL *ch;
CURLcode res;
ch = curl_easy_init();
if(!ch)
return "chfail";
curl_easy_setopt(ch, CURLOPT_URL, "http://google.com/");
curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(ch, CURLOPT_TIMEOUT, 15);
curl_easy_setopt(ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)2011-09-08 13:55:49");
if(proxytype=="http")
curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if(proxytype=="socks4")
curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
if(proxytype=="socks4a")
curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
if(proxytype=="socks5")
curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
if(proxytype=="https")
curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
curl_easy_setopt(ch, CURLOPT_PROXY, ip.c_str());
curl_easy_setopt(ch, CURLOPT_PROXYPORT, port);
curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(ch, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(ch);
curl_easy_cleanup(ch);
if(res == CURLE_OK)
{
if(sizeof(buffer)>0)
return "ok";
else return "fail";
}
else
return curl_easy_strerror(res);
}
First I tried a couple of IPs on a website to check the result I would have to give. This website ( link ), which by the way if you ask why I do not do everything on that website is because I have a couple of thousands of proxies and that web only lets me put 100 maximum at each time.
Returning to the topic, it turns out that:
If proxytype="" and in all cases I have a positive validation (OK)
If proxytype="http" I also have a positive validation (OK)
But if proxytype="https" I have a valid negative, to be more precise the curl_easy_strerror (res) function returns me the following message SSL connect error . (According to the web that proxy if it accepts the HTTPS protocol).
The rest of the cases do not interest me, so I have not tried them.
I've tried putting " link " instead of " link / a> "but it works worse, that is, I do not get any positive cases.
I must add that it is the first time I use libcurl so that is my level right now with this library (Rookie): -)
Well, that, actually I have two questions:
1st - Does anyone know why it is failing with HTTPS connections?
2nd - Could you also use this library to filter IPs by country and eliminate Chinese ones?