Sign in to follow this  
Followers 0
gift8188

how to get the IP information?

22 posts in this topic

hello!

I always use the function following to get the IP information ,but today it can work on one computer . i dont down why.

=====================================================

Dim $DNS[2]

Dim $LocalIP, $LocalMask, $LocalGateway

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objItem In $colItems

$LocalIP = $objItem.IPAddress(0)

$LocalMask = $objItem.IPSubnet(0)

$LocalGateway = $objItem.DefaultIPGateway(0)

$DNS[0] = $objItem.DNSServerSearchOrder(0)

$DNS[1] = $objItem.DNSServerSearchOrder(1)

Next

=====================================================

i ask for help...

i want to get all the information ,including ip address, Subnet mask,Gateway,and DNS.

i also want it can work on vista and xp...

Thanks...

Share this post


Link to post
Share on other sites



hello!

I always use the function following to get the IP information ,but today it can work on one computer . i dont down why.

=====================================================

Dim $DNS[2]

Dim $LocalIP, $LocalMask, $LocalGateway

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objItem In $colItems

$LocalIP = $objItem.IPAddress(0)

$LocalMask = $objItem.IPSubnet(0)

$LocalGateway = $objItem.DefaultIPGateway(0)

$DNS[0] = $objItem.DNSServerSearchOrder(0)

$DNS[1] = $objItem.DNSServerSearchOrder(1)

Next

=====================================================

i ask for help...

i want to get all the information ,including ip address, Subnet mask,Gateway,and DNS.

i also want it can work on vista and xp...

Thanks...

Not enough information. What goes wrong? Have you put a COM error handler in, and does it catch anything?

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

What is $colComputers for? Can't see any reason why you have it there.

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $strDefaultIPGateway = $objItem.DefaultIPGateway(0)
      $Output = $Output & "DefaultIPGateway: " & $strDefaultIPGateway & @CRLF
      $Output = $Output & "DNSDomain: " & $objItem.DNSDomain & @CRLF
      $Output = $Output & "DNSHostName: " & $objItem.DNSHostName & @CRLF
      $strDNSServerSearchOrder = $objItem.DNSServerSearchOrder(0)
      $Output = $Output & "DNSServerSearchOrder: " & $strDNSServerSearchOrder & @CRLF
      $strIPAddress = $objItem.IPAddress(0)
      $Output = $Output & "IPAddress: " & $strIPAddress & @CRLF
      $strIPSubnet = $objItem.IPSubnet(0)
      $Output = $Output & "IPSubnet: " & $strIPSubnet & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif

For more information: http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx

Share this post


Link to post
Share on other sites

thanks

i know the problems

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For another way which will give an alternative if yours fails again

ipconfig()
;~ --------------------------------------------------------------------------------
#cs Possible things to have returned
        Host Name 
        Primary Dns Suffix 
        Node Type 
        IP Routing Enabled
        WINS Proxy Enabled
        DNS Suffix Search List
        Media State 
        Description 
        Physical Address
        Connection-specific DNS Suffix 
        Description
        Physical Address
        Dhcp Enabled
        Autoconfiguration Enabled 
        IP Address
        Subnet Mask 
        Default Gateway
        DHCP Server 
        DNS Servers
        Lease Obtained
        Lease Expires
#ce
;~ --------------------------------------------------------------------------------
Func ipconfig($lookfor = "IP Address")
    $cmd = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
    $Result = ""
    While 1
        $line = StdoutRead($cmd)
        If @error Then Return "Error"
        if StringInStr($line,$lookfor) then ExitLoop
    WEnd
    $Data = StringSplit(StringStripWS($line,7),$lookfor,1)
    $Data = StringSplit($Data[2],":",1)
    $Data = StringStripWS($Data[2],7)
    ConsoleWrite (@CR & $lookfor & "=" &$Data)
    Return $Data
EndFunc

Cheers

wakido

Edited by NBJ

Share this post


Link to post
Share on other sites

For another way which will give an alternative if yours fails again

ipconfig()
;~ --------------------------------------------------------------------------------
#cs Possible things to have returned
        Host Name 
        Primary Dns Suffix 
        Node Type 
        IP Routing Enabled
        WINS Proxy Enabled
        DNS Suffix Search List
        Media State 
        Description 
        Physical Address
        Connection-specific DNS Suffix 
        Description
        Physical Address
        Dhcp Enabled
        Autoconfiguration Enabled 
        IP Address
        Subnet Mask 
        Default Gateway
        DHCP Server 
        DNS Servers
        Lease Obtained
        Lease Expires
#ce
;~ --------------------------------------------------------------------------------
Func ipconfig($lookfor = "IP Address")
    $cmd = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
    $Result = ""
    While 1
        $line = StdoutRead($cmd)
        If @error Then Return "Error"
        if StringInStr($line,$lookfor) then ExitLoop
    WEnd
    $Data = StringSplit(StringStripWS($line,7),$lookfor,1)
    $Data = StringSplit($Data[2],":",1)
    $Data = StringStripWS($Data[2],7)
    ConsoleWrite (@CR & $lookfor & "=" &$Data)
    Return $Data
EndFuncoÝ÷ Ø(^z»0jH£ú®¢×+Ù÷öÜ(®Gè®gµ©e¦[¬Ýý²z-jYhÂ)àémxrßz·¢³Z´+¢×ºÚ"µÍÛÛÛÛUÜ]JÙ]TÛÛYÊ    ][ÝÓØØ[XHÛÛXÝ[Û][ÝË   ][ÝÒTYÜÉ][ÝÊJB[ÈÙ]TÛÛYÊ  ÌÍÓSÛÛXÝ[Û   ÌÍÔÙXÚÝ[ÊHÑÜXÈÛHHÝ][HÜÈÙÈ[ÈÝY^ÙXÚÝ]È[ÙHYÝ[ÈÝ[ØØ[    ÌÍÛ[BØØ[   ÌÍØÛÛXÝ[ÛÝ[ØØ[    ÌÍÝ[YBßKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKBØÜÈÜÜÚXH[ÜÈÈ]H]YÜÝ[YH[XHÈÝY^ÙHHTÝ][È[XYÒSÈÞH[XYÈÝY^ÙXÚÝYYXHÝ]HØÜ[ÛÚXØ[YÜÂÛÛXÝ[ÛÜXÚYXÈÈÝY^ØÜ[ÛÚXØ[YÜÂÜ[XY]]ØÛÛYÝ][Û[XYTYÜÂÝX]XÚÈY][Ø]]Ø^BÔÙÈÙÂXÙHØZ[YXÙH^ÂØÙBß[ÛÛYÂÌÍØÛYH[ÛÛÜXÈ   [È ][ÝÈØÈÛÛYÈØ[    ][ÝËÞÝ[QÕ×ÒQKÍ
BßÙ]ÛYÝ]]HÝÜÛÜÚ[ÜÚ[HBIÌÍÛ[HH  ÌÍÛ[H    [ÈÝÝ]XY
    ÌÍØÛY
BRYÜ[BQ^]ÛÜQ[YÙ[ß[[ÝH[YYYÂÌÍÛ[OTÝ[ÜXÙJ ÌÍÛ[KÒL
K   ][ÝÉ][ÝÊBß[[ÝHXY[ÈÚÜXÙBÌÍÛ[OTÝ[ÔÝÔÊ   ÌÍÛ[KJBß[[ÝHZ[[ÈÚ]ÜXÙBÌÍÛ[OTÝ[ÔÝÔÊ ÌÍÛ[KBßXZÙH[^HÈÜ]YXXÚ]ÌÍÛ[OTÝ[ÔÜ]
    ÌÍÛ[KÒLÊJBßÝ][H[^HÈH^H[ÝÜ ÌÍÚHHHÈ ÌÍÛ[VÌBBßT[[HY[HÈÝÝ]ÜXYÂZYÝ[Ó[  ÌÍÚJHHH[BPÛÛÛÛUÜ]J  ][ÝÓ[H    ][ÝÈ  [È ÌÍÚH [È ][ÝÈ][ÝÈ    [È ÌÍÛ[VÉÌÍÚWH  [ÈÚLÊJBQ[ÙBBPÛÛÛÛUÜ]J  ][ÝÓ[H    ][ÝÈ  [È ÌÍÚH [È ][ÝÎ][ÝÈ    [È ÌÍÛ[VÉÌÍÚWH  [ÈÚLÊJBQ[YBßXÚXÚÚ[ÈÜXÜÙXÝ[Û
Ü][[XÈÜ]ØHÞÝ[ÊBZYÝ[Ò[Ý    ÌÍÛ[VÉÌÍÚWK  ÌÍÓSÛÛXÝ[ÛH[ ÌÍØÛÛXÝ[ÛÝ[HYBBTÙ[XÝPØÙH    ÌÍÔÙXÚÝ[ÈH   ][ÝÒÜÝ[YI][ÝÂBIÌÍÝ[YHHÛÛ][YBPØÙH   ÌÍÔÙXÚÝ[ÈH   ][ÝÔ[XHÈÝY^ ][ÝÂBZYÝÛÛYÔÙ    ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBPØÙH ÌÍÔÙXÚÝ[ÈH   ][ÝÓÙHI][ÝÂBZYÝÛÛYÔÙ  ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBPØÙH ÌÍÔÙXÚÝ[ÈH   ][ÝÒTÝ][È[XY    ][ÝÂBZYÝÛÛYÔÙ    ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBPØÙH ÌÍÔÙXÚÝ[ÈH   ][ÝÕÒSÈÞH[XY   ][ÝÂBZYÝÛÛYÔÙ    ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBPØÙH ÌÍÔÙXÚÝ[ÈH   ][ÝÑÈÝY^ÙXÚÝ ][ÝÈÑÜXÈÛHHÝ][HÈÜÈÙÂBZYÝÛÛYÔÙ  ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBPØÙH[ÙBBZY  ÌÍØÛÛXÝ[ÛÝ[HYH[ÝÛÛYÔÙ  ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊHH[ ÌÍÝ[YHHÛÛYÔÙ ÌÍÛ[VÉÌÍÚWK  ÌÍÔÙXÚÝ[ÊBQ[Ù[XÝ^ÛÛÛÛUÜ]J ][ÝÑPQÉÌÌÎÈÙ]TÛÛYÈ[YN    ][ÝÈ  [È ÌÍÝ[YH   [ÈÔBZY    ÌÍÝ[YHH  ][ÝÉ][ÝÈ[T][ÙJBQ[ÙBT] ÌÍÝ[YJBQ[Y[[Â[ÈÛÛYÔÙ   ÌÍÛ[K    ÌÍÔÙXÚÝ[ÊBSØØ[ ÌÍØÛÝ[SØØ[   ÌÍÝ[YBBZYÝ[Ò[Ý    ÌÍÛ[K    ÌÍÔÙXÚÝ[ÊH[IÌÍÛ[HHÝ[ÔÜ]
    ÌÍÛ[K    ][ÝÎ][ÝÊBIÌÍÛ[HH ÌÍÛ[VÌBNß[[ÝHXY[ÈÚÜXÙBIÌÍÛ[OTÝ[ÔÝÔÊ   ÌÍÛ[KJBNß[[ÝHZ[[ÈÚ]ÜXÙBIÌÍÛ[OTÝ[ÔÝÔÊ   ÌÍÛ[KBIÌÍÝ[YHH    ÌÍÛ[BPÛÛÛÛUÜ]J  ][ÝÑPQÉÌÌÎÈÛÛYÔÙ[YN  ][ÝÈ  [È ÌÍÝ[YH   [ÈÔB] ÌÍÝ[YJBQ[Y[[

Share this post


Link to post
Share on other sites

nice one. much better.

Thanks

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi,

I would like show the subnet mask of my computer and i tried to use your script but i can't have it works.

Here is what i tried

ipconfig()
;~ --------------------------------------------------------------------------------
#cs Possible things to have returned
Host Name
Primary Dns Suffix
Node Type
IP Routing Enabled
WINS Proxy Enabled
DNS Suffix Search List
Media State
Description
Physical Address
Connection-specific DNS Suffix
Description
Physical Address
Dhcp Enabled
Autoconfiguration Enabled
IP Address
Subnet Mask
Default Gateway
DHCP Server
DNS Servers
Lease Obtained
Lease Expires
#ce
;~ --------------------------------------------------------------------------------
Func ipconfig($lookfor = "IP Address")
$cmd = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
$Result = ""
While 1
$line = StdoutRead($cmd)
If @error Then Return "Error"
if StringInStr($line,$lookfor) then ExitLoop
WEnd
$Data = StringSplit(StringStripWS($line,7),$lookfor,1)
$Data = StringSplit($Data[2],":",1)
$Data = StringStripWS($Data[2],7)
ConsoleWrite (@CR & $lookfor & "=" &$Data)
Return $Data
EndFunc
MsgBox(64,"Resultat du test permettant d'etablir un diagnostic de votre machine", & $Data)

I also tried this

ipconfig()
;~ --------------------------------------------------------------------------------
#cs Possible things to have returned
Host Name
Primary Dns Suffix
Node Type
IP Routing Enabled
WINS Proxy Enabled
DNS Suffix Search List
Media State
Description
Physical Address
Connection-specific DNS Suffix
Description
Physical Address
Dhcp Enabled
Autoconfiguration Enabled
IP Address
Subnet Mask
Default Gateway
DHCP Server
DNS Servers
Lease Obtained
Lease Expires
#ce
;~ --------------------------------------------------------------------------------
Func ipconfig($lookfor = "IP Address")
$cmd = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
$Result = ""
While 1
$line = StdoutRead($cmd)
If @error Then Return "Error"
if StringInStr($line,$lookfor) then ExitLoop
WEnd
$Data = StringSplit(StringStripWS($line,7),$lookfor,1)
$Data = StringSplit($Data[2],":",1)
$Data = StringStripWS($Data[2],7)
ConsoleWrite (@CR & $lookfor & "=" &$Data)
Return $Data
EndFunc
MsgBox(64,"Resultat du test permettant d'etablir un diagnostic de votre machine", & ipconfig($lookfor = "IP Address"))

(You noticed that i only add one line at the end of the script)

But in both case i get this error message:

Error: Variable used without being declared.

And it's for the line 41, the one with the MsgBox command.

Any guidance or help would be appreciate.

Thanks

Edited by Kkweit

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

???

MsgBox(64,"Resultat du test permettant d'etablir un diagnostic de votre machine", ipconfig("IP Address"))
Edited by omikron48

Share this post


Link to post
Share on other sites

???

MsgBox(64,"Resultat du test permettant d'etablir un diagnostic de votre machine", ipconfig("IP Address"))

Sorry, it's not IP Address it's Subnet Mask like this:

MsgBox(64,"Resultat du test permettant d'etablir un diagnostic de votre machine", & ipconfig($lookfor = "Subnet Mask"))

But still ! I got this message:

Error: Variable used without being declared.

and still ! i didn't found out how got it work !

If somebody could help me that would be great !

Share this post


Link to post
Share on other sites

It seems that I didn't include a file in my script !

I don't know if it's the source of my problem and I even don't know what is the name of the file that i have to include if i have to.

Is there anybody who got an idea ?

Any help or guidance would be appreciate.

thanks

Share this post


Link to post
Share on other sites

When you call a function you do NOT call it like

ipconfig($lookfor = "Subnet Mask")

Call it with

ipconfig("Subnet Mask")

so your MsgBox() line is incorrect.

BTW: Having a function named ipConfig is bad practice in general. rename that function to _ipConfig for the sake of safety. Don't use DOS or Windows commands as function names and you also can not use AutoIt function names as private function names

Func FileRead($sFile = "") will not work whereas Func _FileRead($sFile = "") will work fine


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I tried this, but was getting Default Gateway as well (when trying to get the Subnet Mask), so have modified the function a little...

;~ --------------------------------------------------------------------------------
#cs Possible things to have returned
        Host Name 
        Primary Dns Suffix 
        Node Type 
        IP Routing Enabled
        WINS Proxy Enabled
        DNS Suffix Search List
        Media State 
        Description 
        Physical Address
        Connection-specific DNS Suffix 
        Description
        Physical Address
        Dhcp Enabled
        Autoconfiguration Enabled 
        IP Address
        Subnet Mask 
        Default Gateway
        DHCP Server 
        DNS Servers
        Lease Obtained
        Lease Expires
#ce
;~ --------------------------------------------------------------------------------
Func _ipconfig($lookfor = "IP Address")
    Local $command
    Local $line = ""
    Local $aRegExp[1]
    
    $command = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
    While 1
        $line = StdoutRead($command)
        If @error Then Return "Error"
        if StringInStr($line,$lookfor) then ExitLoop
    WEnd
        ;don't return but match "IP Address" followed by any character any number of times followed by ":" followed by " ", and 
        ;return between 1 and 3 digits followed by "." followed by between 1 and 3 digits followed by a "." then
        ;between 1 and 3 digits followed by "." followed by  between 1 and 3 digits.

    $aRegExp = StringRegExp($line, "(?:" & $lookfor & ".*:\h)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", 1)  ;
    
    if @error = 0 Then
        Return StringStripWS($aRegExp[0], 3) ;strip trailing/leading spaces, 
    Else
        return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

I found an old script. Maybe it is usefull for you!

Global $ip = "localhost"
If $CmdLine[0] > 0 Then $ip = $CmdLine[1]

$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2")

ConsoleWrite("Systemname;Adapter;Description;IP;Subnet;Gateway;MAC;DNS;DNS Suffix;WINS1;WINS2;DHCP Server" & @CRLF)
ConsoleWrite(Network($ip) & @CRLF)

Func Network($srv)
    Local $col2Items, $Network, $j, $tmp
    Local $Net_Description, $Net_Adapter, $Net_IP, $Net_Subnet, $Net_GW, $Net_MAC, $Net_DNSSearchOrder, $Net_DNSDomainSuffixSearchOrder, $Net_Wins1, $Net_Wins2, $Net_DHCP_Server
    $Network = ""
    $colItems = $objWMIService.ExecQuery("SELECT DHCPServer, Description, WINSPrimaryServer, WINSSecondaryServer, MACAddress, DefaultIPGateway, IPAddress, IPSubnet, DNSServerSearchOrder, DNSDomainSuffixSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30)
    $col2Items = $objWMIService.ExecQuery("SELECT MACAddress, NetConnectionID FROM Win32_NetworkAdapter")

    If IsObj($colItems) Then
        $Network = ""
        For $objItem In $colItems
            $Net_Adapter = ""
            $Net_Description = ""
            $Net_DHCP_Server = ""
            $Net_DNSSearchOrder = ""
            $Net_DNSDomainSuffixSearchOrder = ""
            $Net_GW = ""
            $Net_IP = ""
            $Net_MAC = ""
            $Net_Subnet = ""
            $Net_Wins1 = ""
            $Net_Wins2 = ""

            $Net_Description = $objItem.Description

            If IsObj($col2Items) Then
                For $obj2Item In $col2Items
                    If $objItem.MACAddress = $obj2Item.MACAddress And $obj2Item.NetConnectionID <> "" Then
                        $Net_Adapter = $obj2Item.NetConnectionID
                    EndIf
                Next
                ;If $Net_Adapter = "" Then $Net_Adapter = $Net_Description
            EndIf

            $Net_Wins1 = $objItem.WINSPrimaryServer
            $Net_Wins2 = $objItem.WINSSecondaryServer
            $Net_MAC = $objItem.MACAddress

            For $x = 0 To UBound($objItem.IPAddress) - 1
                $Net_IP &= $objItem.IPAddress($x) & ", "
            Next
            $Net_IP = Remove_Last_Comma($Net_IP)

            For $x = 0 To UBound($objItem.IPSubnet) - 1
                $Net_Subnet &= $objItem.IPSubnet($x) & ", "
            Next
            $Net_Subnet = Remove_Last_Comma($Net_Subnet)

            For $x = 0 To UBound($objItem.DefaultIPGateway) - 1
                $Net_GW &= $objItem.DefaultIPGateway($x) & ", "
            Next
            $Net_GW = Remove_Last_Comma($Net_GW)

            For $x = 0 To UBound($objItem.DNSServerSearchOrder) - 1
                $Net_DNSSearchOrder &= $objItem.DNSServerSearchOrder($x) & ", "
            Next
            $Net_DNSSearchOrder = Remove_Last_Comma($Net_DNSSearchOrder)

            For $x = 0 To UBound($objItem.DNSDomainSuffixSearchOrder) - 1
                $Net_DNSDomainSuffixSearchOrder &= $objItem.DNSDomainSuffixSearchOrder($x) & ", "
            Next
            $Net_DNSDomainSuffixSearchOrder = Remove_Last_Comma($Net_DNSDomainSuffixSearchOrder)

            If $objItem.DHCPServer <> "255.255.255.255" Then $Net_DHCP_Server = $objItem.DHCPServer

            $Network &= $srv & ";" & $Net_Adapter & ";" & $Net_Description & ";" & $Net_IP & ";" & $Net_Subnet & ";" & $Net_GW & ";" & $Net_MAC & ";" & $Net_DNSSearchOrder & ";" & $Net_DNSDomainSuffixSearchOrder & ";" & $Net_Wins1 & ";" & $Net_Wins2 & ";" & $Net_DHCP_Server & @CRLF
        Next
    EndIf
    Return $Network
EndFunc ;==>Network

Func Remove_Last_Comma($str)
    If StringRight($str, 2) = ", " Then $str = StringMid($str, 1, StringLen($str) - 2)
    If StringRight($str, 1) = "," Then $str = StringMid($str, 1, StringLen($str) - 1)
    Return $str
EndFunc ;==>Remove_Last_Comma

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I tried using NBJ's script from earlier in this thread but it did not work for me, so I've developed it a little further so that it works for me and have added another function which will calculate the broadcast address. I've only tested on XP but I thought I would post the code here in case anyone wants it.

#include <Array.au3>
Dim $BroadcastAddress
$BroadcastAddress = GetBroadcastAddress()
Msgbox(0,"Broadcast Address", $BroadcastAddress)
Func GetIPconfig($LookFor)
#cs Possible things to have returned
  Host Name
  Primary Dns Suffix
  Node Type
  IP Routing Enabled
  WINS Proxy Enabled
  DNS Suffix Search List
  Media State
  Description
  Physical Address
  Connection-specific DNS Suffix
  Description
  Physical Address
  Dhcp Enabled
  Autoconfiguration Enabled
  IP Address
  Subnet Mask
  Default Gateway
  DHCP Server
  DNS Servers
  Lease Obtained
  Lease Expires
#ce
Dim $LookFor
$CmdWindow = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4)
$CmdResult = ""
While 1
  $CmdResult = $CmdResult & StdoutRead($CmdWindow)
  If @error Then ExitLoop
WEnd
$TempArray = StringSplit($CmdResult, $LookFor, 1)
$TempArray = StringSplit($TempArray[2], ": ", 1)
$TempArray = StringSplit($TempArray[2], @CR, 1)
$ReturnValue = $TempArray[1]
Return $ReturnValue
EndFunc
Func GetBroadcastAddress()
Dim $BroadcastAddressArray[5]
Dim $ReturnValue
Dim $AddressOctet
$IPaddressTempArray = StringSplit(GetIPconfig("IP Address"), ".")
$SubnetMaskTempArray = StringSplit(GetIPconfig("Subnet Mask"), ".")
For $AddressOctet = 1 to 4
  $BroadcastAddressArray[$AddressOctet] = BitOr($IPaddressTempArray[$AddressOctet], (255 - $SubnetMaskTempArray[$AddressOctet]))
Next
$ReturnValue = _ArrayToString($BroadcastAddressArray, "." , 1)
Return $ReturnValue
EndFunc

Share this post


Link to post
Share on other sites

WHERE IPEnabled = True", "WQL", 0x30)

Hi all,

Despite this is an older discussion and not as live anymore, I notice that this kind of WMI request is commonly used and could not find any other valid WMI request string.

Such a pity that my personal experience is that the resulting list is not what I expect - I get virtual interfaces (VPN adapters) listed as well as a physical network adapters.

Could anyone give me a hint how to narrow up the request to get rid of those and have only physical adapters listed.

BTW the alternative using netsh is

netsh diag show adapter

P.S. I've heard of parameter PhysicalAdapter, but it seems to be usable only in Win2k8 Server, and might be in Win7.

Also can anyone comment on following approach and why it's not working for me? Look here

Share this post


Link to post
Share on other sites

You can extend the WMI query like this (my 1st idea)

$colItems = $objWMIService.ExecQuery("SELECT DHCPServer, Description, WINSPrimaryServer, WINSSecondaryServer, MACAddress, DefaultIPGateway, IPAddress, IPSubnet, DNSServerSearchOrder, DNSDomainSuffixSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE (IPEnabled = True AND NOT Caption LIKE '%VMware%' AND NOT Caption LIKE '%VirtualBox%')", "WQL", 0x30)

It will strip out network cards named *VMware" and "VirtualBox".

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thx for the hint and bump, UEZ

Being inspired, I went on more googling and found kewl tool - WMICOdeCreator from MS.

It has hinted me at bit different class (Win32_NetworkAdapter instead of Win32_NetworkAdapterConfiguration), and it worked like a charm:

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE (NOT PNPDeviceID LIKE '%ROOT%')", "WQL", 0x30)

Thing is, as it went out, that all real HW network cards would be PCI or whatever bus, but not "ROOT\".

Share this post


Link to post
Share on other sites

using win32_networkadaptor all you have to do is look at $obj.physicaladaptor

that just returns true or false


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

@GEOSoft: that is not working because the virtual network adapters have also PhysicalAdapter = True setting. :oops:

Probably because they are build up on physical adapters.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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