添加错误修复
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const axios = require('axios');
|
||||
const net = require('net');
|
||||
const dns = require('dns').promises;
|
||||
const db = require('./db');
|
||||
|
||||
/**
|
||||
@@ -27,9 +29,22 @@ function normalizeGeo(geo) {
|
||||
return geo;
|
||||
}
|
||||
|
||||
async function getLocation(ip) {
|
||||
// Normalize IP (strip port if present)
|
||||
const cleanIp = ip.split(':')[0];
|
||||
async function getLocation(target) {
|
||||
// Normalize target (strip port if present)
|
||||
const cleanTarget = target.split(':')[0];
|
||||
|
||||
// Resolve domain to IP if needed
|
||||
let cleanIp = cleanTarget;
|
||||
if (net.isIP(cleanTarget) === 0) {
|
||||
try {
|
||||
console.log(`[Geo Service] Resolving domain to IP: ${cleanTarget}`);
|
||||
const lookup = await dns.lookup(cleanTarget);
|
||||
cleanIp = lookup.address;
|
||||
} catch (err) {
|
||||
console.error(`[Geo Service] DNS resolution failed for ${cleanTarget}:`, err.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip local/reserved IPs
|
||||
if (isLocalIp(cleanIp)) {
|
||||
|
||||
Reference in New Issue
Block a user