d

WMI Network Card Settings

Display IP Address, Default Gateway, DNS, MAC Address for Network Adapters on a host

//***************************************************************************
// 
// WMI Win32_NetworkAdapterConfiguration dump (JScript)
//
// This script demonstrates how to dump properties from instances of
// Win32_NetworkAdapterConfiguration
//
//***************************************************************************

var service = GetObject('winmgmts:')
var Systems = new Enumerator (service.InstancesOf("Win32_NetworkAdapterConfiguration") );

for (;!Systems.atEnd();Systems.moveNext())
{
    var System = Systems.item();
    print( System.Description );

    var ips = wArray2jArray( System.IPAddress );
    var msk = wArray2jArray( System.IPSubnet );
    var igw = wArray2jArray( System.DefaultIPGateway );

    for( i = 0; i < ips.length; i++ )
    {
        print( "  IP      : " + ips[i] );
        print( "  Mask    : " + msk[i] );
        print( "  Gateway : " + igw[i] );
        print( "" );
    }

    print( "DNS Host    : " + System.DNSHostName );
    print( "IP Enabled  : " + System.IPEnabled );
    print( "MAC Address : " + System.MACAddress );
    print( "----------------------------------------------" );  

}

// Wrap Print
function print( msg )
{
    WScript.Echo( msg );
}

// Convert to JavaScript Array
function wArray2jArray( ar )
{
    var ip = new Array();
    try {
        var ips = new VBArray( ar ).toArray();
        for( i = 0; i < ips.length; i++ )
            ip[ip.length] = ips[i];
    }
    catch( e ){
        ip[ip.length] = "No IP Address";
    }
    return( ip );
}