|
Post by n00b on Dec 12, 2019 10:14:34 GMT -6
I was working on adding some online functionality to a side project I am working on. I wrote this function to get the Local IP Address of the computer it runs on. It works on Windows, Linux, and Mac.
Function LocalIP$() Select Case OS Case "WINDOWS" s$ = "" temp_file$ = Env("Temp") + "\\rc_tmp_ip.txt" System("ipconfig | findstr /R /C:\qIPv4 Address\q > " + temp_file) f=FreeFile FileOpen(f, temp_file, TEXT_INPUT) While Not EOF(f) s = s + Trim(ReadLine(f)) Wend FileClose(f) n = InStr(s, ":")+1 s = Trim(Mid(s, n, Length(s))) Return s Case "LINUX" s$ = "" temp_file$ = "/tmp/rc_tmp_ip.txt" System("hostname -I | awk '{print $1}' > " + temp_file) f=FreeFile FileOpen(f, temp_file, TEXT_INPUT) While Not EOF(f) s = s + Trim(ReadLine(f)) Wend FileClose(f) s = Trim(s) Return s Case "MAC" s$ = "" temp_file0$ = "/tmp/rc_tmp_en0.txt" temp_file1$ = "/tmp/rc_tmp_en1.txt" System("ipconfig getifaddr en0 > " + temp_file0) System("ipconfig getifaddr en1 > " + temp_file1) f=FreeFile FileOpen(f, temp_file0, TEXT_INPUT) s = Trim(Readline(f)) FileClose(f) If s <> "" Then Return s End If FileOpen(f, temp_file1, TEXT_INPUT) s = Trim(Readline(f)) FileClose(f) return s End Select Return "" End Function
|
|
|
Post by johnno56 on Dec 12, 2019 15:33:20 GMT -6
Cool...
|
|
|
Post by tbird on Dec 14, 2019 14:03:41 GMT -6
Well that's one thing off my to-do list, thank you so much!!
|
|