-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Find a better method #5
Comments
This presents a idea for a new module which obtains the default gateway ( |
Or maybe, it's already been done: https://github.com/mh61503891/node-default-network, not sure I like the child_process dependency thought :) |
Kinda feels like something Node.js should provide, right? Like: en0: [ { default: true, address: 'x.x.x.x', netmask: '255.255.255.0', family: 'IPv4', internal: false } ], |
Totally, in my opinion. Reading up on the topic, it seems Ben wasn't in favor in 2012 and there's node-netroute which looks to be the proper way, but it doesn't support Windows. Maybe it should be brought up again for discussion. |
Definitely. |
Not sure how relevant it is, but I vaguely remember writing code like this myself and having crazy issues with virtual adapters that Windows added for debugging Windows Phone. I don't use Windows for development anymore so I can't reproduce it at this point, but in general, I think Node often just isn't aware of how "internal" an interface really is. |
There's no concept of an "internal" network interface in any OS, but we can somewhat reliably identify such interfaces by them not being the default route target. This would of course break once you introduce VPNs that don't set a default route, but it'd say it's a rare case. |
Why is it returning the last interface IP instead of the first one ? You mean for some other OS the last one is the one ? On my machine os.networkInterfaces() returns the output below, and internal-ip returns 172.17.0.1 for ipv4 and fe80::dc93:37ff:fea5:b088 for ipv6, instead of the expected 192.168.1.200 / fe80::76d4:35ff:fe4c:273f Causing some trouble with castnow: xat/castnow#203
|
It's pretty much just guesswork right now. The proper fix will come once mh61503891/node-default-network#1 is merged. |
Before going so far, returning the first address is not the better way ?.. for *nix it looks like it does |
Should be fixed in v2.0.0. |
Given
the module will wrongly return the VM interface's address. I think we can do better, maybe by utilizing the machine's routing table to find the default gateway.
The text was updated successfully, but these errors were encountered: