Skip to content

Instantly share code, notes, and snippets.

@ganapativs
Forked from szalishchuk/ip.js
Created June 28, 2017 08:30
Show Gist options
  • Save ganapativs/65fbe1c709a8701ec6b84729b3726554 to your computer and use it in GitHub Desktop.
Save ganapativs/65fbe1c709a8701ec6b84729b3726554 to your computer and use it in GitHub Desktop.
Get local external ip address with nodejs
var
// Local ip address that we're trying to calculate
address
// Provides a few basic operating-system related utility functions (built-in)
,os = require('os')
// Network interfaces
,ifaces = os.networkInterfaces();
// Iterate over interfaces ...
for (var dev in ifaces) {
// ... and find the one that matches the criteria
var iface = ifaces[dev].filter(function(details) {
return details.family === 'IPv4' && details.internal === false;
});
if(iface.length > 0) address = iface[0].address;
}
// Print the result
console.log(address);
@343N
Copy link

343N commented Aug 8, 2018

This is useful. Thanks.

@cnscorpions
Copy link

not work 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment