Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: IP detector
name
code content
// 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.()
code 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
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change