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

os.networkInterfaces does not list all interfaces. #498

Open
zenoamaro opened this issue Jan 18, 2015 · 38 comments
Open

os.networkInterfaces does not list all interfaces. #498

zenoamaro opened this issue Jan 18, 2015 · 38 comments
Labels
blocked PRs that are blocked by other issues or PRs. feature request Issues that request new features to be added to Node.js. libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.

Comments

@zenoamaro
Copy link

Adoption of nodejs/node-v0.x-archive#9029.

os.networkInterfaces() does not list all interfaces, but only those that have addresses, excluding for example an unplugged eth0, which can be surprising.

This happens because os.networkInterfaces is actually implemented in terms of GetInterfaceAddresses which calls into uv_interface_addresses (which among other things filters out everything except AF_INET*) making networkInterfaces a bit of a misnomer for what is basically networkInterfaceAddresses.

Though os is at stability 4 already, this behavior can be a bit unexpected. Perhaps we could correct it somewhat without breaking the API, or at least document it. I can think of a few ways to work this out:

  • Leave the method as it is, but document the exceptional behavior in the docs, and leave it to a community module to solve this correctly; or
  • Alias it to os.networkInterfaceAddresses, thus reflecting GetInterfaceAddresses and uv_interface_addresses; or
  • Implement uv_interfaces and rebase os.networkInterfaces() on that and uv_interface_addresses, preserving the current behavior, but listing all interfaces when given a flag.
  1. yes
  2. os
  3. v0.10, v0.12, v1.0.0
@rvagg
Copy link
Member

rvagg commented Jan 22, 2015

os.networkInterfaces({ all: true }) wouldn't be a breaking change, I'm +1 for that; not having the ability to list all interfaces is a bit of a handicap for the platform

@bnoordhuis
Copy link
Member

It would require a (tedious) update to libuv, however. Tedious because it needs to be applied to all platforms and because it's an API change. Whoever wants to pursue that, please file a libuv issue first so we can hash out the details.

@zenoamaro
Copy link
Author

+1 for { all: true } and similar approaches. It's unlikely for networkInterfaces to receive an object with this shape by accident. Conversely, trying to invoke the new behavior on node.js will still return a valid list of interfaces (with down interfaces missing as usual).

I believe libuv would only need a single addition (uv_interfaces and possibly uv_free_interfaces) without changes in existing code. The remaining job of meshing uv_interfaces and uv_interface_addresses together would be entirely done on the io.js bindings. I'll open an issue there and try a POC.

bnoordhuis pushed a commit that referenced this issue Jan 23, 2015
Update the documentation for `os.networkInterfaces` to note that any
interface that has not been assigned an address will not be displayed in
the results

Fixes: #498
PR-URL: #543
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@brendanashworth brendanashworth added the os Issues and PRs related to the os subsystem. label Jan 24, 2015
@piranna
Copy link
Contributor

piranna commented May 20, 2015

+1 for { all: true }. Until that, what workarounds could be used?

@Fishrock123 Fishrock123 added the libuv Issues and PRs related to the libuv dependency or the uv binding. label May 26, 2015
@brendanashworth
Copy link
Contributor

@piranna I don't believe there is a core workaround right now, unless there is an npm module somewhere.

@piranna
Copy link
Contributor

piranna commented May 27, 2015

I don't know of any npm module about this... :-(

@brendanashworth brendanashworth added the feature request Issues that request new features to be added to Node.js. label Aug 2, 2015
@Trott
Copy link
Member

Trott commented Jan 19, 2016

This issue appears to be dormant and doesn't seem likely to get any traction any time soon because it depends on a significant feature appearing in libuv first. Would it be wrong-headed to close this and open something in nodejs/NG instead?

@Fishrock123
Copy link
Member

@Trott Nah, this is still valid IMO. It's the kind of thing that we would add.

@Trott Trott added the blocked PRs that are blocked by other issues or PRs. label Apr 22, 2017
@Trott
Copy link
Member

Trott commented Apr 22, 2017

Adding blocked label because this can't happen until libuv gets the required feature...

@OndroNR
Copy link

OndroNR commented Jul 13, 2017

As workaround, I used undocumented function findalldevs() in pcap npm package (uses binary libpcap library, which must be present on system). I am using live packet capture from pcap module anyway. As time of writing, npm version did not compile on my system, but git master did.

In this example, at least interface en4 is unplugged.

> const pcap = require('pcap');
undefined
> pcap.findalldevs()
[ { name: 'en0', addresses: [ <1 empty item>, [Object] ] },
  { name: 'awdl0', addresses: [ <1 empty item>, [Object] ] },
  { name: 'bridge0', addresses: [] },
  { name: 'en1', addresses: [] },
  { name: 'en2', addresses: [] },
  { name: 'p2p0', addresses: [] },
  { name: 'en4', addresses: [] },
  { name: 'lo0',
    addresses: [ <1 empty item>, [Object], [Object], [Object], [Object] ],
    flags: 'PCAP_IF_LOOPBACK' } ]

Also Cap looks usable. it still needs libpcap installed, but should work on Windows as well.
Edit: just converted my code to Cap as I need Windows support :)

@brtthomp
Copy link

brtthomp commented Mar 6, 2018

Are there any open tickets within libuv currently to keep track of? It would be nice to know if anyone is currently working on this problem.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 7, 2018

There is libuv/libuv#158. I don't think anyone is actively working on it though.

@ryzokuken
Copy link
Contributor

What's the current status on this? Is anyone working on this/it's libuv counterpart?

/cc @nodejs/libuv @cjihrig

@lundibundi
Copy link
Member

lundibundi commented Jul 16, 2018

@ryzokuken So there is this libuv/libuv#219 old PR which has been superseded by this libuv/libuv#1371 but unfortunately there has been no activity for almost a year now. It seems the implementation pretty much stalled.
Edit: ping'ed the author in the PR, let's see, maybe there is a chance.

@ryzokuken
Copy link
Contributor

The upstream PR seems to be stalled, and I attempted to close it. Is this still an issue? We could reformat it so that someone else picks it up.

@antillgrp
Copy link

As workaround, I used undocumented function findalldevs() in pcap npm package (uses binary libpcap library, which must be present on system). I am using live packet capture from pcap module anyway. As time of writing, npm version did not compile on my system, but git master did.

In this example, at least interface en4 is unplugged.

> const pcap = require('pcap');
undefined
> pcap.findalldevs()
[ { name: 'en0', addresses: [ <1 empty item>, [Object] ] },
  { name: 'awdl0', addresses: [ <1 empty item>, [Object] ] },
  { name: 'bridge0', addresses: [] },
  { name: 'en1', addresses: [] },
  { name: 'en2', addresses: [] },
  { name: 'p2p0', addresses: [] },
  { name: 'en4', addresses: [] },
  { name: 'lo0',
    addresses: [ <1 empty item>, [Object], [Object], [Object], [Object] ],
    flags: 'PCAP_IF_LOOPBACK' } ]

Also Cap looks usable. it still needs libpcap installed, but should work on Windows as well.
Edit: just converted my code to Cap as I need Windows support :)

Any other workaround besides pcap?, I tried npm network which uses wmic but opens a console to run the wmic command.

Why is so hard to have something like this, for node:

https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkinterface.getallnetworkinterfaces?view=netframework-4.7.2

@ghost
Copy link

ghost commented Sep 28, 2020

5 years and it's still an issue. Workaround is to rely on another npm package or parse ipconfig / ifconfig (or any other network cmd) yourself.
Any better ideas?

@ShogunPanda
Copy link
Contributor

Since libuv is not working on this and the documentation now clearly states:

Returns an object containing network interfaces that have been assigned a network address.

Shall we just close this?

@pprindeville
Copy link

pprindeville commented Dec 29, 2021

Shall we just close this?

I don't see the point. What if you want to use NodeJS to manage interfaces, including the assignment of addresses, either statically or through DHCP? You'd need to see unprovisioned interfaced so that they might be provisioned.

@ShogunPanda
Copy link
Contributor

I totally agree with you. This is a feature that should exist.

But as there's no support in libuv and neither in glibc (and would love to be wrong, honestly) this cannot be implemented in Node.js core.

Therefore I'm suggesting to close this as a signal for future viewers to look for external solutions (like the one mentioned earlier in this issue) rather than waiting for this to be solved.

WDYT?

@manolopm
Copy link

@ShogunPanda, imho, I think you're wrong about glibc.

@pprindeville talked about getifaddrs() and I think it's the way. I take a look to the man page and there is an example that find all interfaces, the interfaces which have an address (family AF_INET or AF_INET6) and the ones without address yet or other low leves interfaces (family AF_PACKET).

I take a look into libuv code and I think there is an explicit filter to the interfaces that aren't in IF_RUNNING state.

If I take the code of the function and put a printf before the if I could see all my network interfaces (such virtualbox, flanel , veth, and so on) that I can't see in node using os.networkInterfaces

This is just my 5 cents, what do you think?

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Sep 11, 2022
@piranna
Copy link
Contributor

piranna commented Sep 11, 2022

This feature is still missing, how can we move it forward?

@ShogunPanda
Copy link
Contributor

The problem is to understand if libuv and/or glibly support it.
If they don't, there is nothing we can do about it.

@piranna
Copy link
Contributor

piranna commented Sep 11, 2022

Maybe we can implement the missing functionality there...

@github-actions github-actions bot removed the stale label Sep 12, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Mar 12, 2023
@piranna
Copy link
Contributor

piranna commented Mar 12, 2023

This PR has been open for 8 years, and ask for a basic functionality. How can we help to move it forward? There's no npm modules that I know that implement it as an alternative, at least in a sane way...

@bnoordhuis
Copy link
Member

The libuv PR (or PRs - I think there were multiple) stalled, repeatedly. Someone would need to revive it but, honestly, I already spent enough time reviewing it. I don't cherish the thought of spending even more of my free time on it.

@github-actions github-actions bot removed the stale label Mar 13, 2023
@ShogunPanda
Copy link
Contributor

ShogunPanda commented Mar 13, 2023

@bnoordhuis I agree.

Note for people reading this issue: Unless libuv lands the needed PR we cannot implement this, sorry. :(

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Sep 10, 2023
@piranna
Copy link
Contributor

piranna commented Sep 10, 2023

no-stale

Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Mar 10, 2024
@piranna
Copy link
Contributor

piranna commented Mar 11, 2024

No stale.

@piranna
Copy link
Contributor

piranna commented Mar 11, 2024

This is just my 5 cents, what do you think?

@manolopm I think that since you've find the place it needs to fixed, just try to move in on libuv side, to see if we have more luck there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. feature request Issues that request new features to be added to Node.js. libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem.
Projects
Status: Pending Triage
Development

No branches or pull requests