From ec6ab9efdbaa6987437b60a0a9a34247cb71f935 Mon Sep 17 00:00:00 2001 From: life Date: Tue, 11 Dec 2018 17:30:54 +0800 Subject: [PATCH] add node-getmac modules --- node_modules/node-getmac/.npmignore | 7 +++ node_modules/node-getmac/README.md | 7 +++ node_modules/node-getmac/index.js | 36 ++++++++++++ node_modules/node-getmac/package.json | 80 +++++++++++++++++++++++++++ tests/test_getmac.js | 2 + 5 files changed, 132 insertions(+) create mode 100644 node_modules/node-getmac/.npmignore create mode 100644 node_modules/node-getmac/README.md create mode 100644 node_modules/node-getmac/index.js create mode 100644 node_modules/node-getmac/package.json create mode 100644 tests/test_getmac.js diff --git a/node_modules/node-getmac/.npmignore b/node_modules/node-getmac/.npmignore new file mode 100644 index 00000000..4df39155 --- /dev/null +++ b/node_modules/node-getmac/.npmignore @@ -0,0 +1,7 @@ +.DS_Store +node_modules +*.log +test +coverage +out +output diff --git a/node_modules/node-getmac/README.md b/node_modules/node-getmac/README.md new file mode 100644 index 00000000..d387d301 --- /dev/null +++ b/node_modules/node-getmac/README.md @@ -0,0 +1,7 @@ +get local mac in nodejs + +### use +``` javascript +var macAddr = require('node-getmac'); + +// '60:03:08:98:a7:d8' diff --git a/node_modules/node-getmac/index.js b/node_modules/node-getmac/index.js new file mode 100644 index 00000000..347a5cd2 --- /dev/null +++ b/node_modules/node-getmac/index.js @@ -0,0 +1,36 @@ +/** + * @file get local mac address + * @author liulangyu(liulangyu90316@gmail.com) + */ + +var execSync = require('child_process').execSync; +var platform = process.platform; + +module.exports = (function () { + var cmd = { + win32: 'getmac', + darwin: 'ifconfig -a', + linux: 'ifconfig -a || ip link' + }[platform]; + + var regStr = '((?:[a-z0-9]{2}[:-]){5}[a-z0-9]{2})'; + + var macReg = new RegExp('ether\\s' + regStr + '\\s', 'i'); + + try { + var data = execSync(cmd).toString(); + var res = { + win32: new RegExp(regStr, 'i').exec(data), + darwin: macReg.exec(data), + linux: macReg.exec(data) + }[platform]; + + + if (res) { + return res[1]; + } + } + catch (e) { + return ''; + } +})(); diff --git a/node_modules/node-getmac/package.json b/node_modules/node-getmac/package.json new file mode 100644 index 00000000..92706cde --- /dev/null +++ b/node_modules/node-getmac/package.json @@ -0,0 +1,80 @@ +{ + "_args": [ + [ + "node-getmac", + "/Users/life/Documents/kuaipan/leanote/desktop-app" + ] + ], + "_from": "node-getmac@latest", + "_id": "node-getmac@1.0.3", + "_inCache": true, + "_installable": true, + "_location": "/node-getmac", + "_nodeVersion": "8.4.0", + "_npmOperationalInternal": { + "host": "s3://npm-registry-packages", + "tmp": "tmp/node-getmac-1.0.3.tgz_1506680192636_0.27925579715520144" + }, + "_npmUser": { + "email": "liulangyu90316@gmail.com", + "name": "liulangyu316" + }, + "_npmVersion": "5.3.0", + "_phantomChildren": {}, + "_requested": { + "name": "node-getmac", + "raw": "node-getmac", + "rawSpec": "", + "scope": null, + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER" + ], + "_resolved": "https://registry.npmjs.org/node-getmac/-/node-getmac-1.0.3.tgz", + "_shasum": "d2aa25e40fae11762302381b030d58b0e37d686a", + "_shrinkwrap": null, + "_spec": "node-getmac", + "_where": "/Users/life/Documents/kuaipan/leanote/desktop-app", + "author": { + "name": "liulangyu" + }, + "bugs": { + "url": "https://github.com/michaelliu90316/node-getmac/issues" + }, + "dependencies": {}, + "description": "get local mac address. simple and work fine for mac linux and windows.", + "devDependencies": {}, + "directories": {}, + "dist": { + "integrity": "sha512-HEmIX5vFfYgpAH/MHiKgx4g7gCHWkBlmH+8huPk1d2cj73yKAdwcXqEykLpEzcRzIAUrAvd0sZhM/UKURS4xZA==", + "shasum": "d2aa25e40fae11762302381b030d58b0e37d686a", + "tarball": "https://registry.npmjs.org/node-getmac/-/node-getmac-1.0.3.tgz" + }, + "homepage": "https://github.com/michaelliu90316/node-getmac#readme", + "keywords": [ + "node-mac", + "mac-address", + "windows-mac-linux" + ], + "license": "ISC", + "main": "index.js", + "maintainers": [ + { + "email": "liulangyu90316@gmail.com", + "name": "liulangyu316" + } + ], + "name": "node-getmac", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/michaelliu90316/node-getmac.git" + }, + "scripts": { + "test": "npm test" + }, + "version": "1.0.3" +} diff --git a/tests/test_getmac.js b/tests/test_getmac.js new file mode 100644 index 00000000..7c83e4ec --- /dev/null +++ b/tests/test_getmac.js @@ -0,0 +1,2 @@ +var macAddr = require('node-getmac'); +console.log(macAddr)