Created
February 26, 2021 03:54
-
-
Save VonHeikemen/dd288c0f1c3b9c0a12364cf1ab766182 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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