Sign in to follow this  
Followers 0

Get IP Address of computer

3 posts in this topic

Posted

i have my WMI script which queries computer name then displays its IP Address but the message is not displaying as it should be. Need your help with this. the first script is WMI when exdcuted in command propmt it gives the IP address but the second code(AUTOIT script) it failed.

code:

WMI

strComputer = "."

Set objWMIService = GetObject( _

"winmgmts:\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery _

("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet

If Not IsNull(IPConfig.IPAddress) Then

For i=LBound(IPConfig.IPAddress) _

to UBound(IPConfig.IPAddress)

WScript.Echo IPConfig.IPAddress(i)

Next

End If

Next

AUTOIT

Local $IPConfig

$strComputer = Inputbox("IP Address", "Enter computer name to get its IP Address.")

$ping = Ping($strComputer, 500)

If $ping Then

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

$IPConfigSet = $objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For $IPConfig in $IPConfigSet

If $IPConfig.IPAddress <> "" Then

For $i=UBound($IPConfig.IPAddress) to UBound($IPConfig.IPAddress)

MsgBox(0, "", $IPConfig.IPAddress($i))

Next

EndIf

Next

Else

MsgBox(16, "Error", "Could not locate computer.")

EndIf

Share this post


Link to post
Share on other sites



Posted

Does this work for you?

Local $IPConfig
$strComputer = Inputbox("IP Address", "Enter computer name to get its IP Address.")
$ping = Ping($strComputer, 500)
If $ping Then
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$IPConfigSet = $objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For $IPConfig in $IPConfigSet
If $IPConfig.IPAddress <> "" Then 
    For $x = 0 to UBound($IPConfig.IPAddress) - 1
        msgbox(0,"",$IPConfig.IPAddress($x))
    Next
EndIf
Next
EndIf

Share this post


Link to post
Share on other sites

Posted

thanks this works for me. but check out this script. why is that $objWMIService.IPAddress value is not returning any when i run the script?

coz i wanted to include the IP Address value to the list but unfortunately it cannot give any value.

#include <Array.au3>

Local $res

$strComputer = InputBox("Software", "Enter computer name.")

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

$colNicConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For $objWMIService In $colNicConfigs

$res &= $objWMIService.DHCPServer & @CRLF _

& $objWMIService.DNSHostName & @CRLF _

& $objWMIService.MACAddress & @CRLF _

& $objWMIService.WINSPrimaryServer & @CRLF _

& $objWMIService.IPAddress & @CRLF _

& $objWMIService.DNSDomain & @CRLF _

& $objWMIService.Description

Next

MsgBox(64, "Software List", $res)

$aList = StringSplit(StringTrimRight($res, 1), @LF);StringTrimRight removes last @LF

_ArrayDisplay($aList, "List")

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

  • Recently Browsing   0 members

    No registered users viewing this page.