How to check network connection status. 
Author Message
 How to check network connection status.

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.....

Any idea's ???



Sat, 12 Feb 2005 05:18:07 GMT  
 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



Sat, 12 Feb 2005 05:36:21 GMT  
 How to check network connection status.
Cool dude....

That was exactly the thing that I was looking 4....

TNX...


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...
2D400F%40hydro.com

- Show quoted text -

Quote:

> --
> torgeir



Sat, 12 Feb 2005 06:02:52 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Check to see is network connection status

2. Using VBscipt to check Network status....

3. Using VBscipt to check Network status....

4. !VB5: How to check status on a network sharename

5. Checking the Status of a Network Client

6. Check Status of ODBC Connection

7. Checking Winsock Connection Status

8. how to check ado connection transaction status???

9. Help: How Can I Check The Status Of A RAS Connection

10. Detecting dial-up networking connection status

11. How to Check for Network Connection Acc 2 ?

12. Checking Network Connection

 

 
Powered by phpBB® Forum Software