-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_checker.cpp
56 lines (42 loc) · 1.29 KB
/
security_checker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#define CURL_STATICLIB
#include <iostream>
#include <string>
#include <curl/curl.h>
#include "security_checker.h"
#include "json/json.hpp"
#pragma comment(lib, "Normaliz.lib")
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Wldap32.lib")
#pragma comment(lib, "Crypt32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "User32.lib")
using json = nlohmann::json;
// GLOBAL CONFIG
CURL* curl;
CURLcode res;
size_t write_function(void* delivered_data, size_t size, size_t nmemb, std::string* user_data) {
user_data->append((char*)delivered_data, size * nmemb);
return size * nmemb;
}
bool check_country(std::string country) {
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (!curl)
return false;
std::string string_response;
curl_easy_setopt(curl, CURLOPT_URL, "http://ip-api.com/json/");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &string_response);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
return false;
json json_response = json::parse(string_response);
std::string response_country = json_response["country"];
if (response_country != country)
return false;
curl_easy_cleanup(curl);
curl_global_cleanup();
return true;
}