From 4a2ba95d027c73ac4b42eaf3f712516435119ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A0=81=E7=8C=BF?= Date: Tue, 9 Sep 2025 23:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E9=80=92=E7=BD=91?= =?UTF-8?q?=E5=8D=A1=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/index.js | 4 +++- index.js | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/index.js b/config/index.js index dda6e21..a97996a 100644 --- a/config/index.js +++ b/config/index.js @@ -1,4 +1,6 @@ module.exports = { port: 9900, - command: 'ip -6 addr show enp3s0' + command: (interface) => { + return `ip -6 addr show ${interface}` + } } \ No newline at end of file diff --git a/index.js b/index.js index 0740e20..6f0151b 100644 --- a/index.js +++ b/index.js @@ -14,9 +14,14 @@ app.use((req, res, next) => { next(); }); -// 提供接口,查询ubuntu server上的ipv6地址,处理字符串后,序列化为json返回. +/** + * 提供接口,查询ubuntu server上的ipv6地址,处理字符串后,序列化为json返回. + * 案例: https://ip.bmycode.help/ip?interface=enp3s0 + * 参数: interface 网卡名称 + */ app.get('/ip', async (req, res) => { - let output = execSync(command, { encoding: "utf8" }); + let interface = req.query.interface || "enp3s0" + let output = execSync(command(interface), { encoding: "utf8" }); res.json(await ip.parseNetworkInfo(output)) })