How can I check the fraud score for an IP address using Node.js?

To find out the IP2Proxy fraud score for an IP address using IP2Location.io in Node.js, you can use the IP2Location.io API to retrieve geolocation and related data.

  1. We'll assume that you have already installed Node.js and we won't cover that here. You will also need a paid subscription to the Security plan. Subscribe now!
  2. Save the below code into a file called test.js on your computer.
    JavaScript
    
    var https = require('https');
    
    var key = 'YOUR_API_KEY';
    var ip = '8.8.8.8';
    
    let url = 'https://api.ip2location.io/?key=' + key + '&ip=' + ip + '&format=json';
    
    let response = '';
    let req = https.get(url, function (res) {
    	res.on('data', (chunk) => (response = response + chunk));
    	res.on('error', (e) => console.log('ERROR: ' + e));
    	res.on("end", function () {
    		try {
    			myobj = JSON.parse(response);
    			if (myobj['error']) {
    				console.log('ERROR: ' + myobj['error']['error_message']);
    			}
    			else if (myobj.fraud_score !== undefined && myobj.fraud_score !== null) {
    				console.log('The fraud score for IP ' + ip + ' is ' + myobj['fraud_score']  + '.');
    			}
    			else {
    				console.log('ERROR: The fraud_score field requires a paid subscription to the Security plan.');
    			}
    		}
    		catch (e) {
    			console.log('ERROR: Invalid JSON in response.')
    		}
    	});
    });
    			
  3. In the command line, run the below command.
    Bash
    
    node test.js
    			

This script will output the IP2Proxy fraud score of specified IP address. Make sure to replace 8.8.8.8 with the IP address you want and replace YOUR_API_KEY to your own API key.

Other Languages

Unlock Location Insights For Free

Empower your applications with accurate IP geolocation information now.

Try It for Free