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)) })