Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
Created February 26, 2021 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VonHeikemen/dd288c0f1c3b9c0a12364cf1ab766182 to your computer and use it in GitHub Desktop.
Save VonHeikemen/dd288c0f1c3b9c0a12364cf1ab766182 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
const os = require('os');
const getNetworkAddress = (interfaces) => {
for (const name of Object.keys(interfaces)) {
for (const interface of interfaces[name]) {
const {address, family, internal} = interface;
if (family === 'IPv4' && !internal) {
return address;
}
}
}
};
const ip = getNetworkAddress(os.networkInterfaces());
console.log(ip);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment