Skip to content

Instantly share code, notes, and snippets.

// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <utility>
#include <chrono>
#include <vector>
#include <algorithm>
#include <iostream>
@caok
caok / gist:8877936
Created February 8, 2014 07:22
如何在Node.js中获取本机IP地址
//获取本地IP地址
var os = require('os');
var IPv4,hostName;
hostName=os.hostname();
for(var i=0;i<os.networkInterfaces().eth0.length;i++){
if(os.networkInterfaces().eth0[i].family=='IPv4'){
IPv4=os.networkInterfaces().eth0[i].address;
}
}
console.log('----------local IP: '+IPv4);