Skip to content

Instantly share code, notes, and snippets.

@CMQNordic
Last active January 22, 2022 23:50
Show Gist options
  • Save CMQNordic/8c9b7e4736ebcbd2c6f72320cdb222cb to your computer and use it in GitHub Desktop.
Save CMQNordic/8c9b7e4736ebcbd2c6f72320cdb222cb to your computer and use it in GitHub Desktop.
Get internal IP on windows javascript
// Get internal ip
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return
}
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
externalAddress = ifname + ':' + alias + ' ' + iface.address
} else {
// this interface has only one ipv4 address
externalAddress = 'http://' + iface.address.trim() + ':' + devServerPort
}
++alias
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment