Sign in to follow this  
Followers 0
littleclown

Find more than 4 local IPs?

7 posts in this topic

Hello.

I need to get ALL local IP addresses, but without using @IPAddressX (sometimes this just can't "see" IPs). On some PCs I have more than 4 network adapters.

It can be an array, it can be a list - no problem.

Thanks in advanced.

Share this post


Link to post
Share on other sites



ipconfig /all

All you have to do after that is to extract the info from the data returned.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Yes, this is the way that I currently use, but I wonder is there some more.. clear way to do it.

Thanks anyway ;).

Share this post


Link to post
Share on other sites

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

Share this post


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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Great script!

Thank you for the fast reply and happy holidays.

Share this post


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
Sign in to follow this  
Followers 0