@qevxo/ip-geo
Version:
Utility functions for IP location and proxy detection.
34 lines (31 loc) • 995 B
JavaScript
const axios = require("axios");
async function from(loc, ip) {
try {
const res = await axios.get(`https://ipinfo.io/${ip}`);
if (res.status === 200 && res.data.country) {
const country = res.data.country;
return loc === country;
} else {
console.log(res.statusText);
return false;
}
} catch (error) {
console.error('Error fetching location:', error.message);
return false;
}
}
async function isProxy(ip) {
try {
const res = await axios.get(`https://proxycheck.io/v3/${ip}`);
if (res.data.status === "ok") {
return res.data[ip]?.detections?.proxy || false;
} else {
console.log('Status not OK:', res.data.status);
return false;
}
} catch (error) {
console.error('Error checking proxy:', error.message);
return null;
}
}
module.exports = { from, isProxy };