I wanted to check a huge list of proxies that I have because I am only interested in the ones that use the https (SSL) protocol and the ones that are not from China. Looking for a quick way to do it I came across 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 it should give me. This website ( https://hidemy.name/es/proxy-checker/ ), which by the way if you wonder why I don't do everything on that website is because I have a couple of thousand proxies and that website 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 output (OK)
If proxytype="http" I also have a positive output (OK)
But if proxytype="https" I have a negative output, to be more precise the function curl_easy_strerror(res) returns the following message SSL connect error . (According to the web, this proxy does accept the HTTPS protocol).
The rest of the cases do not interest me so I have not tried them.
I have tried to put " https://google.com/ " instead of " http://google.com/ " but it works worse, that is to say that I do not get any positive case.
I should add that it's my first time using libcurl so that's my level right now with this library (Newbie) :-)
Well, I actually have two questions:
1º- Does anyone know why it is failing with HTTPS connections?
2º-Could you also use this library to filter the IPs by country and eliminate the Chinese ones?
Seeing that no one has answered me, I am going to answer myself since I have found a solution and maybe it will be useful to someone else. Well, that to know those that support the HTTPS protocol and with a certificate can be done with this function.
Can someone help me filter China proxies? :-)
In addition, another problem has arisen and that is that some proxies have filters (fortinet) that do not let you connect to some websites... I would like to be able to rule out proxies that use those filters as well. Basically it would check if you can connect to that website through that proxy. Does anyone know how to do it?