Giter Club home page Giter Club logo

Comments (11)

silverwind avatar silverwind commented on September 21, 2024

This presents a idea for a new module which obtains the default gateway (en0) and related data like its address. This is something I'd have a personal use case for with node-pcap.

from internal-ip.

silverwind avatar silverwind commented on September 21, 2024

Or maybe, it's already been done: https://github.com/mh61503891/node-default-network, not sure I like the child_process dependency thought :)

from internal-ip.

sindresorhus avatar sindresorhus commented on September 21, 2024

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 } ],

from internal-ip.

silverwind avatar silverwind commented on September 21, 2024

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.

from internal-ip.

sindresorhus avatar sindresorhus commented on September 21, 2024

Maybe it should be brought up again for discussion.

Definitely.

from internal-ip.

timdp avatar timdp commented on September 21, 2024

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.

from internal-ip.

silverwind avatar silverwind commented on September 21, 2024

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.

from internal-ip.

bugdanov avatar bugdanov commented on September 21, 2024

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

{ lo: 
   [ { address: '127.0.0.1',
       netmask: '255.0.0.0',
       family: 'IPv4',
       mac: '00:00:00:00:00:00',
       internal: true },
     { address: '::1',
       netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
       family: 'IPv6',
       mac: '00:00:00:00:00:00',
       scopeid: 0,
       internal: true } ],
  eth0: 
   [ { address: '192.168.1.200',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '74:d4:35:4c:27:3f',
       internal: false },
     { address: 'fe80::76d4:35ff:fe4c:273f',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '74:d4:35:4c:27:3f',
       scopeid: 2,
       internal: false } ],
  'eth0:1': 
   [ { address: '10.3.0.1',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '70:f2:af:03:00:00',
       internal: false } ],
  docker0: 
   [ { address: '172.17.0.1',
       netmask: '255.255.0.0',
       family: 'IPv4',
       mac: '02:42:37:e8:9b:74',
       internal: false },
     { address: 'fe80::42:37ff:fee8:9b74',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '02:42:37:e8:9b:74',
       scopeid: 4,
       internal: false } ],
  veth4a10a10: 
   [ { address: 'fe80::d096:c4ff:fe03:de95',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'd2:96:c4:03:de:95',
       scopeid: 6,
       internal: false } ],
  vethc75935d: 
   [ { address: 'fe80::dcb4:b8ff:fea6:8bd',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'de:b4:b8:a6:08:bd',
       scopeid: 8,
       internal: false } ],
  vethb486c1e: 
   [ { address: 'fe80::d8e3:ff:fe75:c5d6',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'da:e3:00:75:c5:d6',
       scopeid: 10,
       internal: false } ],
  veth19625c8: 
   [ { address: 'fe80::d6:dcff:fe8c:257e',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '02:d6:dc:8c:25:7e',
       scopeid: 12,
       internal: false } ],
  vethc6f5da6: 
   [ { address: 'fe80::b40b:64ff:fecf:8585',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'b6:0b:64:cf:85:85',
       scopeid: 14,
       internal: false } ],
  vethf77529e: 
   [ { address: 'fe80::4c49:43ff:fe2a:a9b4',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '4e:49:43:2a:a9:b4',
       scopeid: 16,
       internal: false } ],
  vethb968eb2: 
   [ { address: 'fe80::dc93:37ff:fea5:b088',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: 'de:93:37:a5:b0:88',
       scopeid: 24,
       internal: false } ] }
> 

from internal-ip.

silverwind avatar silverwind commented on September 21, 2024

It's pretty much just guesswork right now. The proper fix will come once mh61503891/node-default-network#1 is merged.

from internal-ip.

bugdanov avatar bugdanov commented on September 21, 2024

Before going so far, returning the first address is not the better way ?.. for *nix it looks like it does

from internal-ip.

sindresorhus avatar sindresorhus commented on September 21, 2024

Should be fixed in v2.0.0.

from internal-ip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.