#include <iostream>
#include <stdio.h>
#include <string>
#include <Windows.h>
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
using namespace std;
static size_t write_buff_data(char* buffer, size_t size, size_t nitems, void* outstream)
{
memcpy(outstream, buffer, nitems * size);
return nitems * size;
}
// http protocol
int GetHTTPFunc(char* url, char* buff)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "http://hostname:port"); // hostname:port =
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "username:password"); // sub-account and password
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);
curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 2000000L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
return res;
}
else {
printf("http status code:%d", res);
MessageBox(NULL, TEXT("Get IP Error"), TEXT("assistant"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
// Socks5 protocol
int GetSocks5Func(char* url, char* buff)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://hostname:port"); // hostname:port =
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "username:password"); //sub-account and password
curl_easy_setopt(curl, CURLOPT_SOCKS5_AUTH, CURLAUTH_SOCKS5_USERPWD);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data); // Callback
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);
curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 2000000L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
return res;
}
else {
printf("status code:%d", res);
MessageBox(NULL, TEXT("Get IP Error"), TEXT("assistant"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
int func()
{
string strUrl = "ipinfo.io";
char* buff = (char*)malloc(1024 * 1024);
memset(buff, 0, 1024 * 1024);
//HTTP proxies
memset(buff, 0, 1024 * 1024);
GetHTTPFunc((char*)strUrl.c_str(), buff);
printf("Http results:%s", buff);
//Socks5 proxies
memset(buff, 0, 1024 * 1024);
GetSocks5Func((char*)strUrl.c_str(), buff);
printf("Socks5 result:%s", buff);
free(buff);
return 0;
}
int main()
{
return func();
}