Jump to content

_GetLocalIPAddressList (WMI)


Recommended Posts

just was working on somethingelse, stumbled upon an efficient way of getting all Local adapter IP Addresses :-)

donno if @IPAddress1 , etc returns the same thing but Object Error handling is to be added to my script i will do it later

#include <Array.au3>

#cs ; Example
$IPAddresses = _GetLocalIPAddress_WMI()
_ArrayDisplay($IPAddresses, "LocalIPAddressListing")
#ce 

; #FUNCTION# ;===============================================================================
;
; Name...........: __GetLocalIPAddress_WMI
; Description ...: Returns an array of IP Addresses as available from all Local NetworkAdapters installed 
; Syntax.........: _GetLocalIPAddress_WMI()
; Parameters ....: None Defined 
; Return values .: Success - Array Containing the IP Addresses
;                  Failure - Returns 0 and Sets @Error to Error returned by WMI Object
; Author ........: Rajesh V R
; Version .......; 1.0
; Modified.......: 05 May 2009
; Remarks .......:
; Related .......: 
; Link ..........; 
; Example .......; Yes
;
; ;==========================================================================================

Func _GetLocalIPAddress_WMI()

    Local $retArray[1]
    Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
    Local $IPConfigSet = $objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration ")
    For $IPConfig In $IPConfigSet
        $array = $IPConfig.IPAddress
        If IsArray($array) Then
            For $i = 0 To UBound($array) - 1
                _ArrayAdd($retArray, $array[$i])
            Next
        EndIf
    Next

    Return $retArray
EndFunc   ;==>_GetLocalIPAddress_WMI
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...