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

Question, is index 0 always default interface? #3

Open
7c opened this issue Nov 10, 2018 · 2 comments
Open

Question, is index 0 always default interface? #3

7c opened this issue Nov 10, 2018 · 2 comments
Assignees
Labels

Comments

@7c
Copy link

7c commented Nov 10, 2018

given this example:

var data = await getInterfaces()
        names = Object.keys(data);
        console.log(os.networkInterfaces()[names[0]]);

is the interface with index 0 always the default route interface?

@mh61503891
Copy link
Owner

Thank you for your question.

is the interface with index 0 always the default route interface?

No. The order of names depends on a result of a command such as netstat -r -A inet. This library collects default-gateways form multiple network interfaces.

@mh61503891 mh61503891 self-assigned this Nov 15, 2018
@7c
Copy link
Author

7c commented Oct 10, 2019

i have a linux ubuntu 16.04 with 2.6.32 kernel and output of netstat is:

$:netstat -rn -A inet
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 venet0

based on

getDefaultNetworkByInet4 = (callback) ->
  getDefaultNetwork "netstat -rn -A inet | awk '$4~/UG/ {print $2,$8;}'",
    (error, data) ->
      callback(error, data)

you require a G flag in netstat. This approach worked until i have seen this 2.6.32 host

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

No branches or pull requests

2 participants