How to Check if an IP address is a Tor Exit Node Server using C/C++

Cloudmersive
1 min readJul 18, 2023

--

Tor exit nodes can sometimes indicate imminent malicious activity, so it’s important to be aware when they’re visiting our network. Using the below code, we can take advantage of an API that quickly identifies if an input address is a tor exit node, allowing us to monitor that IP address’ activity more closely.

We can easily structure our API call in C/C++ by first installing libcurl:

libcurl/7.75.0

And then copying & pasting the ready-to-run code examples below:

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-tor-node");
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);

We can authorize up to 800 API requests per month for free by providing a free-tier Cloudmersive API key in the authorization header.

After that, you’re all set — no more code required.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.