Created
July 20, 2014 15:19
-
-
Save supersha/4667023b3d483bc28102 to your computer and use it in GitHub Desktop.
获取mac下的ip地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
var exec = require("child_process").exec; | |
exec("ifconfig", function(err, stdout){ | |
if(err){ console.log(err); return; } | |
var string = stdout; | |
//inet 10.68.141.98 netmask 0xfffffc00 broadcast 10.68.143.255 | |
var reg = /inet\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\snetmask.+broadcast/; | |
if(reg.test(string)){ | |
console.log(RegExp.$1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment