mirror of
https://github.com/lyz05/danmaku.git
synced 2026-04-14 02:20:05 +08:00
feat: 增加批量解析域名与查询IP信息的方法
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user