electron +VUE 获取本地MAC地址
以下仅在windows10下 做过测试
import { networkInterfaces } from 'os'
let mac = ''
function getMac() { try { if (mac != '' && mac != 'unknown' && mac != null && mac != undefined) { console.log('mac不为空,直接返回') return mac } const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/ const list = networkInterfaces() for (const [key, parts] of Object.entries(list)) { // for some reason beyond me, this is needed to satisfy typescript // fix https://github.com/bevry/getmac/issues/100 if (!parts) continue for (const part of parts) { if (zeroRegex.test(part.mac) === false) { mac = part.mac console.log('mac', mac) } } } } catch (err) { mac = 'unknown' } return mac }