Mirror: Best-effort discovery of the machine's local network using just Node.js dgram sockets
1# lan-network
2
3**Best-effort discovery of the machine's default gateway and local network IPv4 address exclusively with UDP sockets.**
4
5This utility attempts to determine the interface and IPv4 address of a machine
6on the local network. It'll attempt to determine the default gateway and
7return the corresponding network interface assignment, both when the network
8is online and offline.
9
10The LAN Network it attempts to pick is the one that the machine uses to connect
11to the internet. Determining it is useful to pick the machine's IP address that
12is generally used to connect to it from other devices on the network.
13
14`lanNetwork()` makes three separate attempts to guess the local network:
15
161. Create a socket to a publicly routed IP, and return the assignment matching the socket's local address
172. Broadcast DHCP discovery packets on all routable network assignments and listen for replies
183. Highest priority assignment
19
20`lanNetworkSync()` does the same synchronously by spawning a child process
21and blocking until a result is determined. Using this method is generally
22not recommended.