;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WMINicInfo() 
;; 
;;ACTION         Returns an array of arrays containing descriptions of each NIC 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION	 1.0  - 2008/11/01 
;; 
;;HISTORY        1.0  - 2008/11/01 - Initial Release 
;; 
;;SYNTAX         WMINicInfo([target] [,WMIAuth]) 
;; 
;;PARAMETERS     Target - OPTIONAL - String 
;;               - The name of system to query 
;; 
;;               AuthPtr - OPTIONAL - Object 
;;               - The pre-authenticated WMI object pointer. 
;;                 Use WMIAuthenticate() udf to create the AuthPtr value. 
;;                 AuthPtr is not needed if user has admin rights. 
;; 
;;REMARKS        Returns info about all physical NICs in a given system.  
;;               DHCP Lease times are in GMT 
;;               Status (15) is only returned reliably on XP and higher systems. 
;;		 Note that WMI queries are blocked by default on Vista and higher systerms 
;;		 and must be permitted on the client firewall, otherwise this func returns  
;;		 "RPC Server Unavailable". 
;; 
;;RETURNS        Array of arrays 
;;                - the first element of the array represents each NIC 
;;                - the second element represents one of 20 distinct NIC parameters 
;;                 NIC Elements: 
;;                -  0 : Adapter Description 
;;                -  1 : Manufacturer 
;;                -  2 : NIC GUID 
;;                -  3 : NULL 
;;                -  4 : Speed/Duplex text 
;;                -  5 : Driver Version 
;;                -  6 : DHCP boolean (1=Use DHCP) 
;;                -  7 : IP settings  (address,mask,gateway) *, ** 
;;                -  8 : Domain Info: Hostname;Connection;Primary;Search List **, *** 
;;                -  9 : DNS Server list ** 
;;                - 10 : DHCP Server, Lease Aquired, Lease Expires (if DHCP is enabled) 
;;                - 11 : WINS Server list ** 
;;                - 12 : Interface Name 
;;                - 13 : Fixed Name Servers 
;;                - 14 : Reserved for future use 
;;                - 15 : NIC Status (2=Ready,0=Disabled...) 
;;                - 16 : MAC Address - only if NIC is enabled/connected 
;;                - 17 : NULL 
;;                - 18 : NULL 
;;                - 19 : NULL 
;; 
;;                NULL values are returned for unsupported fields to maintain compatability 
;;                with NicInfo() 
;; 
;;                * If multiple IP addresses are assigned to a NIC, the IP addresses will 
;;                be presented as a space-delimited list, followed by a semicolon and the  
;;                space-delimited list of corresponding netmasks, followed by a semicolon and the 
;;                space-delimited list of corresponding gateways (usually just one) 
;;                 
;;                ** Any time multiple values are returned, they will be space delimited 
;; 
;;		  *** Individual sections are ";" delimited - for example, the IP Settings value 
;;                contains 3 sections. If there were 2 IP addresses, the data returned would have 
;;                the format "IP1 IP2;MASK1 MASK2;GATEWAY" 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    NT4, W2K, WXP, W2K3 
;; 
;;EXAMPLES        
;;                $Array = NicInfo($COMPUTER) 
;;                If UBound($Array) < 0 
;;                  @SERROR ? 
;;                Else 
;;                  UBound($Array) + 1 ' NICs found.' ? 
;;                  For $X = 0 to UBound($Array) 
;;                    For $Y = 0 to UBound($Array[$X]) 
;;                      $y '. ' $Array[$X][$Y] ? 
;;                    Next 
;;                  Next 
;;                EndIf 
; 
Function WMINicInfo(OPTIONAL $_Target, OPTIONAL $_pAuth)
 
  Dim $_SI[19]						; Var for return array 
  Dim $_, $_Delim					; temp var, delimiter char 
  Dim $_aSi, $_P					; outer array of data arrays, Pointer 
  Dim $_SRoot
  Dim $_WFile
  Dim $_OSVer
  Dim $_objWMIService, $_colItems, $_objItem		; Primary WMI object vars 
  Dim $_colItems2, $_objItem2				; Secondary WMI object vars 
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Target = IIf(Not $_Target, '.', Join(Split($_Target,'\'),''))
 
  ; If a pre-authenticated WMI object pointer was provided, use it, otherwise create a new object pointer 
  If $_pAuth
    $_objWMIService = $_pAuth
  Else
    $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Target + '\root\cimv2')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  $_P = -1
 
; Network Adapter SECTION		####################################### 
 
  ; NetworkAdapter	======================================================= 
  $_colItems = $_objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
  For Each $_objItem in $_colItems
    If InStr($_objItem.AdapterType, 'Ethernet')
      $_P = $_P + 1
      Redim Preserve $_aSi[$_P]
      $_Si[0]  = $_objItem.ProductName
      $_Si[1]  = $_objItem.Manufacturer
      $_Si[2]  = $_objItem.GUID
      $_Si[4]  = $_objItem.Speed
      $_Si[12] = $_objItem.NetConnectionID
      $_Si[15] = $_objItem.NetConnectionStatus
      $_Si[16] = $_objItem.MACAddress
      $_Si[14] = $_objItem.PNPDeviceID		; needed by next phase 
 
; Network Driver SECTION		####################################### 
 
      ; PnPSignedDriver	======================================================= 
      $_colItems2 = $_objWMIService.ExecQuery("Select * from Win32_PnPSignedDriver",,48)
      For Each $_objItem2 in $_colItems2
        If InStr($_objItem2.DeviceID, $_Si[14])
          $_Si[5]  = $_objItem2.DriverVersion + ' (' + $_objItem2.DriverProviderName + ')'
        EndIf
      Next
      $_colItems  = 0	; clear pointer 
      $_Si[14] = ''		; clear temp reference 
 
; Network Adapter Config SECTION	####################################### 
 
      ; NetworkAdapterConfiguration	=============================================== 
      $_colItems2 = $_objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
      For Each $_objItem2 in $_colItems2
        If InStr($_objItem2.SettingID, $_Si[2])
          $_Si[6]  = Abs($_objItem2.DHCPEnabled)
          $_Delim = ''
          For Each $_ in $_objItem2.IPAddress
            If Not InStr($_, ':')
              $_SI[7] = $_SI[7] + $_Delim + $_
              $_Delim = ' '
            EndIf
          Next
          $_Si[7]  = $_Si[7] + ';'
          $_Delim = ''
          For Each $_ in $_objItem2.IPSubnet
            If InStr($_, '.')
              $_SI[7] = $_SI[7] + $_Delim + $_
              $_Delim = ' '
            EndIf
          Next
          $_Si[7]  = $_Si[7] + ';'
          $_Delim = ''
          For Each $_ in $_objItem2.DefaultIPGateway
            If Not InStr($_, ':')
              $_SI[7] = $_SI[7] + $_Delim + $_
              $_Delim = ' '
            EndIf
          Next
          $_Si[8]  = $_objItem2.DNSHostName + ';' + $_objItem2.DNSDomain
          $_Delim = ''
          For Each $_ in $_objItem2.DNSServerSearchOrder
            If Not InStr($_, ':')
              $_SI[9] = $_SI[9] + $_Delim + $_
              $_Delim = ' '
            EndIf
          Next
          $_Si[10] = $_objItem2.DHCPServer + ';' + FixDate($_objItem2.DHCPLeaseObtained) + ';' + FixDate($_objItem2.DHCPLeaseExpires)
          $_Si[11] = $_objItem2.WINSPrimaryServer
          If $_objItem2.WINSSecondaryServer
            $_Si[11] = $_Si[11] + ';' + $_objItem2.WINSSecondaryServer
          EndIf
        EndIf
      Next
      $_colItems2  = 0	; clear pointer 
 
      $_aSi[$_P] = $_Si				; add sub-array to master array 
    EndIf
  Next
  $_colItems2  = 0	; clear pointer 
 
  ; Return the array 
  $WMINicInfo= $_aSi
  Exit 0
 
EndFunction
 
; FixDate - convert the datetime string to yyyy/mm/dd hh:mm:ss format, ignoring TZ offset 
Function FixDate($_DateStamp)
 
  Dim $_
 
  $FixDate = Left($_DateStamp, 4) + '/' + SubStr($_DateStamp, 5, 2) + '/' + SubStr($_DateStamp, 7, 2) + ' '
  $FixDate = $FixDate + SubStr($_DateStamp, 9, 2) + ':' + SubStr($_DateStamp, 11, 2) + ':' + SubStr($_DateStamp, 13, 2)
 
  Exit 0
 
EndFunction