Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Get IP Address of computer


  • Please log in to reply
2 replies to this topic

#1 JohnRichard

JohnRichard

    Prodigy

  • Active Members
  • PipPipPip
  • 196 posts

Posted 02 September 2008 - 09:15 AM

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







#2 covaks

covaks

    Polymath

  • Active Members
  • PipPipPipPip
  • 249 posts

Posted 02 September 2008 - 09:24 AM

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


#3 JohnRichard

JohnRichard

    Prodigy

  • Active Members
  • PipPipPip
  • 196 posts

Posted 02 September 2008 - 09:52 AM

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")




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users