Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Using a Proxy Server from a Windows C++ Applicaiton

0.00/5 (No votes)
31 Jan 2021 1  
Possible ways to use a Proxy Server within a Windows C++ application
Proxy servers are used to provide extra security. A Proxy Server is a gateway between users and the internet. Software products would use it for various purposes such as scrapping data from the Internet.

Introduction

ProxyRack is one of the few proxy service providers which provide a residential VPN service. I came across their services while working on a Facebook data scrapper. ProxyRack claims to serve more than 800 million API requests per day, and while the lack of details about the company doesn’t inspire confidence, its pricing and features make it an attractive option worth exploring.

Proxycrack Open Source code samples can be found here.

This demo tries a Proxy SDK, via its REST API, and checks a web sites that returns your public IP. http://ip-api.com, a eree for non-commercial use, Easy to integrate service, available in JSON, XML, CSV, Newline, PHP.

Video Demo

In this demo, Proxycrack is used as part of a software for scrapping all comments of a given Facebook post.

Demo Video

My demo is a Command Line based software component created for the purpose of demonstration of the Proxyrack SDK using C++ (Visual Studio C++) and LibCurl.

Integrating with libCurl

As part of this demo, I wanted to use libCurl as a static library. I managed to do so, and the static library is part of the source code. I found this answer useful.

Initiating libCurl

First, we initiate the Curl object:

Even though the curl_easy_init() function must be the first function to call, we first call curl_global_init(), which sets up the program environment that libcurl needs.

curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init.html();

Making the Request

In this demonstration, we use one of the rotating residental IP addresses provided by the API, and at the same time, use a 3rd party service which will return our public IP, so we can see if the IP indeed changes.

CURL* curl = curl_easy_init();
if (curl)
{
    /* General Proxy */
    curl_easy_setopt(curl, CURLOPT_PROXY, "http://mixed.rotating.proxyrack.net:444");
    curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, L"<YOURUSERNAME>");
    curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, L"<YOURPASSWORD>");
    curl_easy_setopt(curl, CURLOPT_URL, "http://ip-api.com/json");
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

Obtaining the Results

In more complex cases, you would need to add, at this point, some code which will interpret the results returned by the CURL request, and structure it (for example, as .csv or .JSON). In this specific case, the results are printed on screen.

Logging

The WriteLogFile() function is used instead of wprintf() and carries the task of displaying debug messages in the DEBUG version and writing to a log file (in both DEBUG / RELEASE versions).

Technology

  • The Software was developed using Visual Studio Enterprise C++ 2017.
  • LibCurl is used as a static library.

History

  • 31st January, 2021: Initial version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here