indutny/node-ip

returns localhost (127.0.0.1) as publicIpv4

Opened this issue · 2 comments

returns localhost (127.0.0.1) as publicIpv4

ip.address returns 127.0.0.1 which isn't my publicIpv4 address.. how do I get what I want

the issue title seems to imply a bug, however it is just the intended behaviour. see the documentation for that:

// ### function address (name, family)
// #### @name {string|'public'|'private'} **Optional** Name or security
//      of the network interface.
// #### @family {ipv4|ipv6} **Optional** IP family of the address (defaults
//      to ipv4).
//
// Returns the address for the network interface on the current system with
// the specified `name`:
//   * String: First `family` address of the interface.
//             If not found see `undefined`.
//   * 'public': the first public ip address of family.
//   * 'private': the first private ip address of family.
//   * undefined: First address with `ipv4` or loopback address `127.0.0.1`.

so you would have to call ip.address('public') however depending on where you will run that code it might not return an IP address at all. If you are behind a NAT router or in any other kind of network that works with private IP addresses (e.g. a server behind loadbalancers), your computer/ server does not have a public ip address, your network has, but that won't show up on your computers interfaces.