我只需要根据他们的计算机了解用户,而不是使用用户注册到数据库。我认为使用计算机的 ip 地址会有所帮助,但如果有其他选择,我愿意了解它。这是我正在使用的代码:
const { networkInterfaces } = require('os');
const getLocalIP = () => {
const nets = networkInterfaces();
const results = Object.create(null);
for (const name of Object.keys(nets)) {
for (const net of nets[name]) {
if (net.family === 'IPv4' && !net.internal) {
if (!results[name]) {
results[name] = [];
}
results[name].push(net.address);
return net.address
}
}
}
}
exports.getLocalIP = getLocalIP