electron-vue 怎么获取客户端ip

electron-vue 怎么获取客户端ip

阅读 10.1k
2 个回答

先安装依赖 npm install ip

代码里面添加
const ip = require('ip');
const IPAddress = ip.address();
console.log(IPAddress);

新手上路,请多包涵

let interfaces = require('os').networkInterfaces();

        for (let devName in interfaces) {
            let iface = interfaces[devName];
            for (let i = 0; i < iface.length; i++) {
                let alias = iface[i];
                if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                    this.Ip=alias.address
                }
            }
        }
        
       
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏