To detect if an IP address is a VPN using IP2Location.io in Node.js, you can use the IP2Location.io API to retrieve geolocation and related data.
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['proxy']) {
if (myobj['proxy']['is_vpn']) {
console.log('The IP ' + ip + ' is a VPN.');
}
else {
console.log('The IP ' + ip + ' is NOT a VPN.');
}
}
else {
console.log('ERROR: The is_vpn field requires a paid subscription to the Security plan.');
}
}
catch (e) {
console.log('ERROR: Invalid JSON in response.')
}
});
});
node test.js
This script will check if the specified IP address is a VPN. Make sure to replace 8.8.8.8 with the IP address you want and replace YOUR_API_KEY to your own API key.
Empower your applications with accurate IP geolocation information now.
Try It for Free