
How to check network connection status.
Quote:
> Hi all...
> I would like to check a server status via script.
> The only problem is that I can't determine if the server is avalible.
> If I cannot reach the server, my WMI connection inside the script goes all
> wrong.....
Ping it. The function below takes a hostname or IP address as input:
If IsConnectible("myserver01", 2, 900) Then
WScript.Echo "Connected!"
Else
WScript.Echo "Not connected!"
End If
Function IsConnectible(sHost,iPings,iTO)
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"
oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Select Case InStr(sResults,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
End Function
For other ping solutions, look at:
Subject: Re: ping command return values
Newsgroups: microsoft.public.scripting.VBScript
Date: 2002-06-14 07:10:41 PST
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3D09...
--
torgeir