From 26ac7b5637d0949c7df5b7fe47fa3e86cb9da572 Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Fri, 8 Dec 2023 18:34:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=9F=9F=E5=90=8D=E4=B8=8E=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?IP=E4=BF=A1=E6=81=AF=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/airportsub.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/routes/airportsub.js b/routes/airportsub.js index 14b459c..2ca0f84 100644 --- a/routes/airportsub.js +++ b/routes/airportsub.js @@ -7,6 +7,9 @@ const {filesize} = require("filesize"); const moment = require("moment"); const axios = require("axios"); const leancloud = require("../utils/leancloud"); +const libqqwry = require("lib-qqwry"); +const dns = require("dns"); +const qqwry = libqqwry(); //初始化IP库解析器 // TODO 迁移到leancloud @@ -173,6 +176,45 @@ router.get("/download", async function (req, res) { }); +// 域名解析函数 +function resolveDomain(domain) { + return new Promise((resolve, reject) => { + dns.lookup(domain, (error, address) => { + if (error) { + reject(error); + } else { + resolve(address); + } + }); + }); +} + +async function proc(url) { + try { + const response = await axios.get(url); + const info = yaml.load(response.data, { schema: yaml.FullSchema }); + + for (const line of info.proxies) { + // 过滤解析结果相同的 IP + try { + const ipaddr = await resolveDomain(line.server); + const ipLoc = qqwry.searchIP(ipaddr); //查询IP信息 + line.server = ipaddr; + console.log(line.name, line.server, ipLoc.Country, ipLoc.Area); + } catch { + console.log(line.name, line.server); + continue; + } + } + + const updatedInfo = yaml.dump(info, { skipInvalid: true }); + return updatedInfo; + } catch (error) { + console.error(error); + return yamldata; + } +} + module.exports = router; if (!module.parent) {