Skip to content

Instantly share code, notes, and snippets.

@supersha
Created July 20, 2014 15:19
Show Gist options
  • Save supersha/4667023b3d483bc28102 to your computer and use it in GitHub Desktop.
Save supersha/4667023b3d483bc28102 to your computer and use it in GitHub Desktop.
获取mac下的ip地址
#! /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