24
index.js
24
index.js
@@ -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');
|
||||
|
||||
Referencia en una nueva incidencia
Block a user