vue获取主机id和IP地址

2023-12-14 20:31:19

获取主机id和IP地址 在vue.config.js

const os = require(“os”);

function getNetworkIp() {
let needHost = “”; // 打开的host
try {
// 获得网络接口列表
let network = os.networkInterfaces();
for (let dev in network) {
let iface = network[dev];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (alias.family === “IPv4” && alias.address !== “127.0.0.1” && !alias.internal) {
needHost = alias.address;
}
}
}
} catch (e) {
needHost = “localhost”;
}
return needHost;
}

const myHost = getNetworkIp();
const myName = os.hostname();
process.env.VUE_APP_HOST = myHost;//IP地址
process.env.VUE_APP_NAME = myName;//主机名
//生成设备id
const idObj = require(“node-machine-id”);
let id = idObj.machineIdSync({ original: true });

process.env.VUE_APP_MACHINEID = id;//设备id

文章来源:https://blog.csdn.net/weixin_61769998/article/details/134871508
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。