我正在尝试在登录过程中为我的应用程序实现双重身份验证,并希望向用户发送发起登录请求的操作系统和设备名称,但是我已经尝试搜索了解决此问题的方法,但我找到的只适用于后端(nodejs os模块)。是否有任何npm模块或其他方式可以帮助我实现这一目标。
node-geoip
的工具)。例子:
const http = require('http');
const geoip = require('geoip-lite'); // npm install --save geoip-lite -- have a look at https://github.com/bluesmoon/node-geoip to know how to update the datafiles
const Sniffr = require("sniffr"); // npm install --save sniffr
const requestIp = require('request-ip'); // npm install --save request-ip
const HOST = process.env.HOST || '0.0.0.0';
const PORT = process.env.PORT || 1337;
const server = http.createServer((req, res) => {
const userAgent = req.headers['user-agent'];
const s = new Sniffr();
s.sniff(userAgent);
const clientIp = requestIp.getClientIp(req);
const geo = geoip.lookup(clientIp); // will be set to null if server is accessed locally
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({
...s,
clientIp,
geo
}, null, 2));
});
server.listen(PORT, HOST, () => {
console.log(`Server is listening on http://${HOST}:${PORT}`);
});