Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2026-02-12 00:36:42 +01:00
padre f725d02dea
commit 9e5479dd8c
Se han modificado 2 ficheros con 102 adiciones y 12 borrados

Ver fichero

@@ -29,6 +29,7 @@ const ES_CHECK_INTERVAL = config.cache.checkInterval;
// Public IP detection
let publicIP = null;
let publicIPGeoData = null;
// Statistics tracking
const stats = {
@@ -186,11 +187,11 @@ function isPrivateIP(ip) {
}
/**
* Check if IP is remote (not local, not private, not our public IP)
* Check if IP is remote (not local, not private)
* Now includes the public IP for geolocation
*/
function isRemoteIP(ip) {
if (!ip || isPrivateIP(ip)) return false;
if (publicIP && ip === publicIP) return false;
return true;
}
@@ -198,10 +199,15 @@ function isRemoteIP(ip) {
* Get GeoIP information for an IP address
*/
function getGeoIPData(ip) {
if (!ip || !isRemoteIP(ip)) {
if (!ip || isPrivateIP(ip)) {
return null;
}
// Return cached GeoIP data for our public IP
if (publicIP && ip === publicIP && publicIPGeoData) {
return publicIPGeoData;
}
try {
const geo = geoip.lookup(ip);
@@ -825,10 +831,20 @@ async function main() {
process.exit(1);
}
// Get public IP address for GeoIP filtering
// Get public IP address and GeoIP data
try {
publicIP = await getPublicIP();
logger.info(`Detected public IP: ${publicIP}`);
// Get GeoIP data for our public IP
if (publicIP) {
publicIPGeoData = getGeoIPData(publicIP);
if (publicIPGeoData) {
logger.info(`Public IP geolocation: ${publicIPGeoData.city || 'Unknown'}, ${publicIPGeoData.country || 'Unknown'}`);
} else {
logger.warn('Could not determine geolocation for public IP');
}
}
} catch (error) {
logger.warn('Failed to detect public IP address:', error.message);
logger.warn('GeoIP will be applied to all non-private IPs');