Determining the local IP address via script

Why determining the local IP address should be such a monumental task in Windows is anyone’s guess. Here’s some JavaScript code I cobbled together from a couple of different sources for an installer script I’m writing.

function GetIpAddress()
    var ip = "";
    wmi = GetObject("winmgmts:!\\\\.\\root\\cimv2")
    nac = wmi.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    for (nac = new Enumerator(nac); !nac.atEnd(); nac.moveNext())
        ip += nac.item().ipAddress(0);

    if (ip == "")
        throw "IP address not found";
    return ip;

It works but isn’t pretty. Surely there must be an easier way? (I’m not running in a browser so no Remote_Server header is available).

Signed: Irritated

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

Checklist Buddy Available for Testing
Tweetz 2.0.0 Released
Tweetz 2.0 Beta
VSColorOutput 2.7 - Time Stamps
Fixed Focal-Length Eyeglasses, a Programmer's Best Friend
How to Choose the Right VPN Service
Two Handy Command Line Scripts
More... (1089)