Thank you very much for this piece of code! I also need this for a project.
Sorry for bumping this, but I got a few remarks to add :
First, I think this should be useful if integrated in SCLang directly, to facilitate remote communication ? Unfortunately, I don’t know how to use git . But if the addition makes sense, and someone knows how to create a pull request, I’d be happy to help on the integration.
Second thing concerns the linux implementation. On my Ubuntu 22.04 LTS, ifconfig isn’t installed by default. It’s not difficult to install, but I’m working on a software for non-engineers people, and I’d rather have it working ‘out-of-the-box’, with no third party install. In my case, I just want the software to display local IP as text.
I found this command, ip address, which, I think, was installed by default :
ip address | grep "inet " | awk '{print $2}'
But I don’t know if it’s the case for the whole Linux ecosystem.
Also, it outputs the ‘subaddress’ (don’t know how it’s called) : 192.168.1.37 /24.
Should this be removed from the IP ?
As a reference, here’s my ‘updated’ version of the code :
~getLocalIPs = {
var winCMD, macCMD, linCMD, ips;
winCMD = {
var ipInfo, ipv4s;
ipInfo = "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}'")
.unixCmdGetStdOut;
};
ips = Platform.case(
\osx, { macCMD.() },
\linux, { linCMD.() },
\windows, { winCMD.() }
);
ips = ips.split(Char.nl);
ips.removeAt(ips.size-1);
ips
};