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

Configure Feed

Select the types of activity you want to include in your feed.

fix: Fix probe and fallback method for Windows (#9)

* Add designated Microsoft virtual interface MAC

* Add viname by name

* Update probe route to IP/port combo that's definitely publicly routable

* Add changeset

authored by

Phil Pluckthun and committed by
GitHub
6bf9bd3f f4a38998

+25 -5
+5
.changeset/funny-sloths-joke.md
··· 1 + --- 2 + 'lan-network': patch 3 + --- 4 + 5 + Fix probing and fallback methods for Windows
+17 -2
src/network.ts
··· 46 46 }; 47 47 48 48 /** Determines if an assignment is internal (indicated by the flag or by a zeroed mac address) */ 49 - export const isInternal = (assignment: NetworkAssignment) => 50 - assignment.internal || parseMacStr(assignment.mac).every(x => !x); 49 + export const isInternal = (assignment: NetworkAssignment) => { 50 + if (assignment.internal) { 51 + return true; 52 + } 53 + const mac = parseMacStr(assignment.mac); 54 + if (mac.every(x => !x)) { 55 + return true; 56 + } else if (mac[0] === 0 && mac[1] === 21 && mac[2] === 93) { 57 + // NOTE(@kitten): Microsoft virtual interface 58 + return true; 59 + } else if (assignment.iname.includes('vEthernet')) { 60 + // NOTE(@kitten): Other Windows virtual interfaces 61 + return true; 62 + } else { 63 + return false; 64 + } 65 + }; 51 66 52 67 export const interfaceAssignments = (): NetworkAssignment[] => { 53 68 const candidates: NetworkAssignment[] = [];
+3 -3
src/route.ts
··· 1 1 import { createSocket } from 'dgram'; 2 2 3 - const NOOP_PORT = 65535; 4 - const NOOP_IP = '255.255.255.255'; 3 + const PROBE_PORT = 53; 4 + const PROBE_IP = '1.1.1.1'; 5 5 const NO_ROUTE_IP = '0.0.0.0'; 6 6 7 7 class DefaultRouteError extends TypeError { ··· 16 16 socket.close(); 17 17 socket.unref(); 18 18 }); 19 - socket.connect(NOOP_PORT, NOOP_IP, () => { 19 + socket.connect(PROBE_PORT, PROBE_IP, () => { 20 20 const address = socket.address(); 21 21 if (address && 'address' in address && address.address !== NO_ROUTE_IP) { 22 22 resolve(address.address);