To detect if an IP address is a VPN using IP2Location.io in Deno, you can use the IP2Location.io API to retrieve geolocation and related data.
import * as https from "node: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 d = "";
let req = https.get(url, function (res) {
res.on("data", (chunk) => (d = d + chunk));
res.on("end", function () {
if (res.statusCode == 200) {
let data = JSON.parse(d);
if (data.proxy) {
if (data.proxy.is_vpn) {
console.log(
"The IP " + data.ip + " is a VPN.",
);
} else {
console.log(
"The IP " + data.ip + " is NOT a VPN.",
);
}
} else {
console.log(
"ERROR: The is_vpn field requires a paid subscription to the Security plan.",
);
}
} else if (res.statusCode == 400 || res.statusCode == 401) {
if (d.includes("error_message")) {
console.log("ERROR: " + JSON.parse(d).error.error_message);
} else {
console.log(d);
}
} else {
console.log(d);
}
});
});
req.on("error", function (e) {
console.log(e);
});
deno --allow-env --allow-net 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