1
- import http from "http" ;
2
1
import WebSocket from "ws" ;
3
2
import { CoreV1Api , KubeConfig } from "@kubernetes/client-node" ;
4
3
import { execSync } from "child_process" ;
5
4
import vdf from "vdf-parser" ;
6
5
import fs from "fs" ;
7
- import dns from "dns " ;
6
+ import os from "os " ;
8
7
9
8
const kc = new KubeConfig ( ) ;
10
9
kc . loadFromDefault ( ) ;
@@ -139,27 +138,28 @@ async function getNode() {
139
138
}
140
139
141
140
async function getLanIP ( ) {
142
- try {
143
- const node = await getNode ( ) ;
141
+ const interfaces = os . networkInterfaces ( ) ;
142
+ for ( const name of Object . keys ( interfaces ) ) {
143
+ const ips = interfaces [ name ] ;
144
144
145
- const hostname = node . status ?. addresses ?. find (
146
- ( addr ) => addr . type === "Hostname" ,
147
- ) ?. address ;
148
- if ( hostname ) {
149
- return await new Promise ( ( resolve , reject ) => {
150
- dns . lookup ( hostname , ( err , address ) => {
151
- if ( err ) {
152
- reject ( err ) ;
153
- }
154
-
155
- console . info ( `lan ip: ${ address } ` ) ;
156
-
157
- resolve ( address ) ;
158
- } ) ;
159
- } ) ;
145
+ if ( ! ips ) {
146
+ continue ;
147
+ }
148
+
149
+ for ( const { family, address, internal } of ips ) {
150
+ if (
151
+ internal ||
152
+ family !== "IPv4" ||
153
+ name . startsWith ( "tailscale" ) ||
154
+ name . startsWith ( "cni" )
155
+ ) {
156
+ continue ;
157
+ }
158
+
159
+ console . info ( `lan ip: ${ address } ` ) ;
160
+
161
+ return address ;
160
162
}
161
- } catch ( error ) {
162
- console . warn ( `unable to get lan ip` , error ) ;
163
163
}
164
164
}
165
165
@@ -186,24 +186,6 @@ process.once("SIGUSR2", () => {
186
186
187
187
setupWebSocket ( ) ;
188
188
189
- const hostname = "0.0.0.0" ;
190
- const port = 80 ;
191
-
192
- const server = http . createServer ( ( req , res ) => {
193
- if ( req . url === "/ping" ) {
194
- console . info ( "GOT PING" ) ;
195
- res . statusCode = 200 ;
196
- res . end ( ) ;
197
- } else {
198
- res . statusCode = 404 ;
199
- res . end ( "Not Found" ) ;
200
- }
201
- } ) ;
202
-
203
- server . listen ( port , hostname , ( ) => {
204
- console . log ( `ping endpoint is ready.` ) ;
205
- } ) ;
206
-
207
189
async function getCsVersion ( ) {
208
190
if ( ! fs . existsSync ( "/serverfiles/steamapps/appmanifest_730.acf" ) ) {
209
191
return ;
0 commit comments