Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is returning 127.0.0.1 #79

Open
Kuchiriel opened this issue Jul 14, 2017 · 1 comment
Open

This is returning 127.0.0.1 #79

Kuchiriel opened this issue Jul 14, 2017 · 1 comment

Comments

@Kuchiriel
Copy link

I am using Arch Linux, I need to retrieve the network interface ip, like 192.168.0.14.
Thanks.

@HMarzban
Copy link

HMarzban commented Oct 25, 2018

It is so easy, first get all interface, then follow code below:

const os = require('os');
const ip = require('ip');

// it gives you array of interfaces,
// you can pick the name of that interface you wanna get IP address
console.log(os.networkInterfaces()); 

ip.address("_interfaceName","ipv4") // you can now obtain the interface IP address you wanted.

or easiest way is get all your interface by this command ifconfig then find the interface that point your IP target, after all easily put that interface name in the ip.address() function. ex:

ip.address("docker")
// or
ip.address("Wi-Fi")

it is better mention here that ip.address() retrive first interface public ip version 4 address and some time is some think like 127.0.0.1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants