This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
module.exports = {
|
||||
port: 9900,
|
||||
command: 'ip -6 addr show enp3s0'
|
||||
command: (interface) => {
|
||||
return `ip -6 addr show ${interface}`
|
||||
}
|
||||
}
|
||||
9
index.js
9
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))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user