Skip to content

Instantly share code, notes, and snippets.

@productdevbook
Created June 20, 2022 07:29
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 productdevbook/d144b69ce6376b62abb7f8812321b60b to your computer and use it in GitHub Desktop.
Save productdevbook/d144b69ce6376b62abb7f8812321b60b to your computer and use it in GitHub Desktop.
Get IP Adress Func
import os from 'node:os'
function getIPAdress() {
let localIPAddress = ''
const interfaces = os.networkInterfaces()
for (const devName in interfaces) {
const iface = interfaces[devName] as os.NetworkInterfaceInfo[]
for (let i = 0; i < iface.length; i++) {
const alias = iface[i]
if (
alias.family === 'IPv4' &&
alias.address !== '127.0.0.1' &&
!alias.internal
) {
localIPAddress = alias.address
}
}
}
return localIPAddress
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment