How to Identify Tor Exit Node Servers with a Free API in Node.js
Tor servers are used to hide the origin of a client server request, and they can sometimes indicate a potential threat to our network.
While we can’t trace the exact origin of a request made through a Tor server, we can sometimes identify if Tor server IP addresses were used to route that request in the first place. We can do that using the ready-to-run code below, which will allow us to leverage a free Network Threat Detection API in our Node.js web applications.
To authorize our requests for free, we’ll just need a free-tier API key. This will allow us to make up to 800 API calls per month with no commitments, and our total will reset the following month.
We can begin structuring our API call by installing the SDK. To do that, we can either run this command:
npm install cloudmersive-security-api-client --save
Or we can add this snippet to our package.json instead:
"dependencies": {
"cloudmersive-security-api-client": "^1.2.0"
}
Finally, we can call the function after we fulfill our request parameters:
var CloudmersiveSecurityApiClient = require('cloudmersive-security-api-client');
var defaultClient = CloudmersiveSecurityApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveSecurityApiClient.NetworkThreatDetectionApi();
var value = "value_example"; // String | IP address to check, e.g. \"55.55.55.55\". The input is a string so be sure to enclose it in double-quotes.
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.networkThreatDetectionIsTorNode(value, callback);
Now we can easily trigger alerts in our network when Tor exit node requests reach our servers.
As an aside, it’s important to note that Tor exit nodes aren’t always indicative of a threat. Tor servers are used for myriad purposes around the world.