NetAddr.myIP on Windows?

Does anyone know if NetAddr.myIP (from NetLib) works on Windows, and if not, is there a way to get the local IP in another way? I am having a very old laptop ensemble piece played, and some of the players are on Windows. Looking at the source, it looks like it only works on mac and linux.

Thanks,

Sam

Yes, the code only works on mac and linux.

Here’s a quick and dirty way to get the local IP on windows:

(
    var p = Pipe("ipconfig | findstr /c:192.168", "r");
    var line = p.getLine;
    var addr = line[line.find("192.168")..];
    addr.postln;
)

Here I’m assuming that the local address starts with 192.168. - which is true for most home networks.

Ooo. Awesome. Does this also work on windows:

(
    var p = Pipe("dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com", "r");
    var line = p.getLine;
    var addr = line[line.find("192.168")..];
    addr.postln;
)

Haha. Never mind. That isn’t the right ip. Dang.

What did you want to do with that last code?

I was just being dumb. I thought I had found a brilliant way to have the code be cross-platform, but I wasn’t looking at what it was actually telling me, which was my public ip, not my local one. But this works nicely on the mac:

(
var p = Pipe("ipconfig getifaddr en0", "r");
var line = p.getLine;
line.postln;
)

Thanks Christof

Sam

I guess the best way to make it cross-platform would be for NetLib to move platform-specific versions of myIP into UnixPlatform and WindowsPlatform, and then have NetAddr *myIP just call thisProcess.platform.myIP.

hjh