Jump to content

Find more than 4 local IPs?


Recommended Posts

Hi,

WMI could be your friend.....

#include <array.au3> ; only needed for _Arraydisplay
Global $arnwadap [1] [2] ; Global array for network adapter and ip
_getnetworkadapter ()
_ArrayDisplay ($arnwadap)

; WMI get only Adapter with ip settings
; If WMI fail or no adapter with ip settings Return 0
Func _getnetworkadapter ()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $found = False
    $strComputer = "localhost"
    $count = 0
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            If StringInStr ($objItem.IPAddress(0), ".") <> 0 Then
                ReDim $arnwadap [$count + 1] [2]
                $arnwadap [0] [0] = $objItem.Caption
                $arnwadap [0] [1] = $objItem.IPAddress(0)
                $count += 1
                $found = True
            EndIf
        Next
        If Not $found Then Return 0
    Else
        Return 0
    EndIf
EndFunc

;-))

Stefan

Link to post
Share on other sites

Thanks for the script, but its not work for me.

I have 2 Vmware network adapters with static IPs

One not connected adapter

And one physical adapter working on DCHP

The result of this script is just information of one of the virtual NICs and 3 blank lines.

Thanks for the help anyway.

Link to post
Share on other sites

Hi,

shame on me........

This should work, tested with 2 VMWare Adapter static IP and one physical NIC with DHCP:

#include <array.au3> ; only needed for _Arraydisplay
Global $arnwadap [1] [2] ; Global array for network adapter and ip
_getnetworkadapter ()
_ArrayDisplay ($arnwadap)

; WMI get only Adapter with ip settings
; If WMI fail or no adapter with ip settings Return 0
Func _getnetworkadapter ()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $found = False
    $strComputer = "localhost"
    $count = 0
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            If StringInStr ($objItem.IPAddress(0), ".") <> 0 Then
                ReDim $arnwadap [$count + 1] [2]
                $arnwadap [$count] [0] = $objItem.Caption ;corrected to $count
                $arnwadap [$count] [1] = $objItem.IPAddress(0) ;corrected to $count
                $count += 1
                $found = True
            EndIf
        Next
    Else
        Return 0
    EndIf
    If Not $found Then Return 0
EndFunc

;-))

Stefan

Edited by 99ojo
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...