Click here to Skip to main content
15,885,537 members
Articles / Programming Languages / C++

Using a Proxy Server from a Windows C++ Applicaiton

Rate me:
Please Sign up or sign in to vote.
4.71/5 (8 votes)
31 Jan 2021CPOL2 min read 8.2K   149   3
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.

C++
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.

C++
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Secured Globe, Inc.
United States United States
Michael Haephrati is a music composer, an inventor and an expert specializes in software development and information security, who has built a unique perspective which combines technology and the end user experience. He is the author of a the book Learning C++ , which teaches C++ 20, and was published in August 2022.

He is the CEO of Secured Globe, Inc., and also active at Stack Overflow.

Read our Corporate blog or read my Personal blog.





Comments and Discussions

 
Questionthoughts Pin
Nelek31-Jan-21 10:11
protectorNelek31-Jan-21 10:11 
AnswerRe: thoughts Pin
Michael Haephrati31-Jan-21 22:29
professionalMichael Haephrati31-Jan-21 22:29 
GeneralRe: thoughts Pin
Nelek31-Jan-21 23:15
protectorNelek31-Jan-21 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.