// title: IP detector // author: prko // description: // This code outputs an array consisting of local IPs (or an array with one local IP if there is only one) except “127.0.0.1”. // // It successfully detects multiple IPv4 addresses as well as one IPv4 address under macOS 12.2.1 and Windows 11. However, under Ubuntu 20.04.3, which ran over Parallels Desktop, I strangely could not assign IPv4 to the second network card. Thus, I confirmed only the output of an array with one IP, but I hope it also could output multiple IPs. // // related post: https://scsynth.org/t/code-to-get-local-ip-on-all-platforms/5791/3?u=prko // code: // The following strings are to avoid listing network bridges which seem to be created by Parallels Desktop: // | grep -Fv "inet 10." ( ~getLocalIPs = { var winCMD, macCMD, linCMD, ips; winCMD = { "ipconfig | findstr /C:IPv4" .unixCmdGetStdOut .replace(" IPv4 Address. . . . . . . . . . . : ", ""); }; macCMD = { ("ifconfig | grep -Fv" + "inet 10." .quote + "| grep" + "inet " .quote + "| grep -Fv 127.0.0.1 | awk '{print $2}'" ).unixCmdGetStdOut; }; linCMD = { ("ip address | grep \"inet \" | grep -Fv 127.0.0.1 | awk '{print $2}' | cut -d '/' -f1") .unixCmdGetStdOut; }; //linCMD = { ( // "ifconfig | grep" + "inet ".quote + // "| grep -Fv 127.0.0.1 | awk '{print $2}'" //).unixCmdGetStdOut }; ips = Platform.case( \osx, { macCMD.() }, \linux, { linCMD.() }, \windows, { winCMD.() } ); ips = ips.split(Char.nl); ips.removeAt(ips.size-1); ips } ) ~getLocalIPs.()