How to Detect Bot Client Threats with a Free API in Node.js
Non-user entities (e.g., bots) on the internet pose a variety of threats to our network. They can be used to steal our information, distribute malware to our servers, or launch Denial of Service attacks on our network, and they can even perpetuate “click fraud” by artificially inflating our content’s web traffic analytics.
Thankfully, using the below code, we can detect bot client threats by using a free API to reference IP addresses against a list (updated in real-time) of known IP address threats. This will offer an important layer of protection for our network, all while requiring minimal code and incurring zero overhead costs.
To authorize our API calls for free, we’ll just need a free-tier API key. These will allow a limit of 800 API calls per month with no additional commitments.
With our API key copied to our clipboard, 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:
"dependencies": {
"cloudmersive-security-api-client": "^1.2.0"
}
Finally, we can use the below code to call the function & process our IP strings for threats:
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.networkThreatDetectionIsBot(value, callback);
That’s all there is to it — no more code required!