|
| 1 | +import { createHash } from 'crypto'; |
| 2 | +import { networkInterfaces } from 'os'; |
| 3 | + |
| 4 | +// Sourced from GKD |
| 5 | +const knownBadAppIds = [ |
| 6 | + // this appId corresponds to the 'iBridge Adapter for the Touchbar' on macbooks |
| 7 | + // https://github.com/bevry/getmac/issues/42 |
| 8 | + // https://discussions.apple.com/thread/7763102 |
| 9 | + // discovered 3/21/23 with ~28,000 unique users |
| 10 | + '8149453d12fde3c987f5ceb011360abe56307d17', // sha1('ac:de:48:00:11:22') |
| 11 | + |
| 12 | + // these appIds correspond to the default VMWARE vnet1 and vmnet8 interface mac address |
| 13 | + // https://communities.vmware.com/t5/VMware-Workstation-Pro/Why-are-MAC-addresses-for-vmnet1-and-vmnet8-hardcoded/td-p/1580213 |
| 14 | + // discovered 3/21/23 with 10250 unique users |
| 15 | + 'a76a6cbfb93cbb6daa4c4836544564fb777a0803', // sha1('00-50-56-C0-00-01') |
| 16 | + // discovered 3/22/23 with 3473 unique users |
| 17 | + '4433e1caaca0b97ba94ef3e0772e5931f792fa9b', // sha1('00-50-56-C0-00-08') |
| 18 | + |
| 19 | + // this appId corresponds to the "Forticlient VPN client" adapter mac address |
| 20 | + // https://community.fortinet.com/t5/Support-Forum/FortiClient-MAC-Address/m-p/60724 |
| 21 | + // discovered 3/21/23 with 5655 unique users |
| 22 | + 'b14e824ad9cd8a3e95493d48e6132ecce40e0e47', // sha1('00-09-0F-FE-00-01') |
| 23 | +]; |
| 24 | + |
| 25 | +// Sourced from https://github.com/bevry/getmac/blob/master/source/index.ts |
| 26 | +// There's issues with importing 'getmac' directly, so we referenced the relevant code here |
| 27 | + |
| 28 | +const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/; |
| 29 | +export function getMac(): string | undefined { |
| 30 | + const list = networkInterfaces(); |
| 31 | + |
| 32 | + for (const parts of Object.values(list)) { |
| 33 | + // for some reason beyond me, this is needed to satisfy typescript |
| 34 | + // fix https://github.com/bevry/getmac/issues/100 |
| 35 | + if (!parts) continue; |
| 36 | + for (const part of parts) { |
| 37 | + if (zeroRegex.test(part.mac) === false) { |
| 38 | + const appId = sha1(part.mac); |
| 39 | + if (appId != null && !knownBadAppIds.includes(appId)) { |
| 40 | + return appId; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + return undefined; |
| 46 | +} |
| 47 | + |
| 48 | +function sha1(data: string): string | undefined { |
| 49 | + return createHash('sha1').update(data, 'utf8').digest('hex'); |
| 50 | +} |
0 commit comments