MCPcopy Create free account
hub / github.com/coder/mux / getNonInternalInterfaceAddresses

Function getNonInternalInterfaceAddresses

src/node/services/serverService.ts:99–134  ·  view source on GitHub ↗
(
  networkInterfaces: NetworkInterfaces,
  family: "IPv4" | "IPv6"
)

Source from the content-addressed store, hash-verified

97}
98
99function getNonInternalInterfaceAddresses(
100 networkInterfaces: NetworkInterfaces,
101 family: "IPv4" | "IPv6"
102): string[] {
103 const addresses: string[] = [];
104 const emptyInfos: os.NetworkInterfaceInfo[] = [];
105
106 for (const name of Object.keys(networkInterfaces)) {
107 const infos: os.NetworkInterfaceInfo[] = networkInterfaces[name] ?? emptyInfos;
108 for (const info of infos) {
109 const infoFamily = info.family;
110
111 if (infoFamily !== family) {
112 continue;
113 }
114
115 if (info.internal) {
116 continue;
117 }
118
119 const address = info.address;
120
121 // Filter out link-local addresses (they are rarely what users want to copy/paste).
122 if (family === "IPv4" && address.startsWith("169.254.")) {
123 continue;
124 }
125 if (family === "IPv6" && address.toLowerCase().startsWith("fe80:")) {
126 continue;
127 }
128
129 addresses.push(address);
130 }
131 }
132
133 return Array.from(new Set(addresses)).sort();
134}
135
136function parseIpv4Octets(address: string): [number, number, number, number] | null {
137 const parts = address.split(".");

Callers 1

computeNetworkBaseUrlsFunction · 0.85

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected