How to Check if an IP Address is a Known Threat using C/C++
It’s important we’re aware immediately when threats including bad Ips, botnets, compromised servers, etc. visit our network. Using the below code, you can use a free API to quickly check input IP addresses against a constantly updated list of known IP address threats, learning instantly which type of threat, if any, a given IP address represented.
To structure your API request, start by installing Libcurl:
libcurl/7.75.0
Next, copy the below code, and then provide a free-tier API key (obtainable on the Cloudmersive website; valid for 800 API calls per month) in the authorization header:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/security/threat-detection/network/ip/is-threat");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "\"<string>\"";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
That’s all there is to it — no more code required!