Posts

Showing posts from February, 2015
Get the IP of a hostname using WMI (vbscript) Purpose find the current IP of a given hostname approach: use the wmi win32_pingstatus to issue a ping, and get value of the returnaddress property sample code strTargethost = "server1.domain.com" Set objWMIService = GetObject("winmgmts:\\") Set PingResults = objWMIService.execquery("Select StatusCode,Address,ProtocolAddress FROM Win32_PingStatus where address = '" & strtargethost & "'") For Each oTarget In PingResults if oTarget.Statuscode   = 0 then  wscript.Echo "Host:" & strTargethost & ", address:" & oTarget.ProtocolAddress else wscript.echo "Host:" & strTargethost & ",status: " & oTarget.Statuscode end if Next