๐Ÿ“ฆ kitten / lan-network

Best-effort discovery of the machine's local network using just Node.js dgram sockets

โ˜… 1 stars โ‘‚ 1 forks ๐Ÿ‘ 1 watching โš–๏ธ MIT License
๐Ÿ“ฅ Clone https://github.com/kitten/lan-network.git
HTTPS git clone https://github.com/kitten/lan-network.git
SSH git clone git@github.com:kitten/lan-network.git
CLI gh repo clone kitten/lan-network
Phil Pluckthun Phil Pluckthun fix: Mark `bridge*` interfaces as internal by default to deprioritize them (#15) 18413d6 2 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .changeset
๐Ÿ“ .github
๐Ÿ“ cli
๐Ÿ“ scripts
๐Ÿ“ src
๐Ÿ“„ .gitattributes
๐Ÿ“„ .gitignore
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ LICENSE.md
๐Ÿ“„ package.json
๐Ÿ“„ pnpm-lock.yaml
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

lan-network

Best-effort discovery of the machine's default gateway and local network IPv4 address exclusively with UDP sockets.

This utility attempts to determine the interface and IPv4 address of a machine on the local network. It'll attempt to determine the default gateway and return the corresponding network interface assignment, both when the network is online and offline.

The LAN Network it attempts to pick is the one that the machine uses to connect to the internet. Determining it is useful to pick the machine's IP address that is generally used to connect to it from other devices on the network.

lanNetwork() makes three separate attempts to guess the local network:

  • Create a socket to a publicly routed IP, and return the assignment matching the socket's local address
  • Broadcast DHCP discovery packets on all routable network assignments and listen for replies
  • Highest priority assignment
lanNetworkSync() does the same synchronously by spawning a child process and blocking until a result is determined. Using this method is generally not recommended.