Jump to content

determine whether a computer on a local network is available through WMI ?


Recommended Posts

Hi guys

Just trying to figure out / wondering if anyone knows the best way to determine whether a computer on a local network is available.

Said computer has a static ip and is running server 2008 standard

I have been playing with the ping command, but it seems sort of sloppy and was hoping that someone might know if it can be done through WMI ? .

Im looking for a persistent way to watch if the server is online and is reachable.

regards

Link to comment
Share on other sites

;## If the system has a particular service you need to verify is available, you can simply connect to that service and validate that way.
;## EXAMPLES

TCPStartup()

TCPConnect("192.168.1.11", 80);  <== Validates HTTP Server
If @error Then
    ;## This Server is Offline.
EndIf

TCPConnect("192.168.1.12", 21);  <== Validates FTP Server
If @error Then
    ;## This Server is Offline.
EndIf

TCPConnect("192.168.1.12", 666);  <== Doom 2 Server
If @error Then
    ;## This Server is Offline.
EndIf

TCPShutdown()

Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

sorry i was searching for what i had used - this is based on script i got from the internet, modified to my use to retrieve IP address also.

' based on [url="http://msdn.microsoft.com/en-us/library/aa394350(loband).aspx"]http://msdn.microsoft.com/en-us/library/aa...50(loband).aspx[/url] (had a tuf time getting to understand simple concepts :-(

URLPath = "www.robvanderwoude.com"
WScript.Echo URLPath & " on-line: " & Ping( URLPath)

URLPath = "www.google.com"
WScript.Echo URLPath & " on-line: " & Ping( URLPath)

URLPath = "Manjara22"
WScript.Echo URLPath & " on-line: " & Ping( URLPath)

URLPath = "Simpleshare"
WScript.Echo URLPath & " on-line: " & Ping( URLPath)


Function Ping(MyHostName)
' This function returns True if the specified host could be pinged.
' myHostName can be a computer name or IP address.
' The Win32_PingStatus class used in this function requires Windows XP or later.
' This function is based on the TestPing function in a sample script by Don Jones
' [url="http://www.scriptinganswers.com/vault/computer%20management/default.asp#activedirectoryquickworkstationinventorytxt"]http://www.scriptinganswers.com/vault/comp...ioninventorytxt[/url]

    ' Standard housekeeping
    Dim colPingResults, objPingResult, strQuery

    ' Define the WMI query
    strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & myHostName & "'" '& " AND ResolveAddressNames = " & True 

    ' Run the WMI query
    Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )

    ' Translate the query results to either True or False
    For Each objPingResult In colPingResults
        If Not IsObject( objPingResult ) Then
            Ping = False
        ElseIf objPingResult.StatusCode = 0 Then
            'WScript.Echo objPingResult.ProtocolAddress
            'Ping = True
            Ping = "True, With the IP" & objPingResult.ProtocolAddress
        Else
            Ping = False
        End If
    Next
    Set colPingResults = Nothing
End Function

its the original vbscript i have, ofcourse, will post autoit script later on if needed.

Edited by rajeshontheweb
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...