• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Network Down?

There are 5 NTs networked on tcp/ip,at my machine i'm trying to have an application run in the background that will tell me when any of these machines are disconnected from the network? Im newbie so be very detailed thanks
0
jbird090897
Asked:
jbird090897
1 Solution
 
shchukaCommented:
One possible solution is to have a timer in VB and in its timer event ping each of the machines, i.e. send something to it and get a responce.  If a machine doesn't respond within some established period of time (say, 5 seconds), you can assume it's off the network.

The pitfall is, though, you need to make sure that the timer interval is longer than the time your whole routine need to execute.  Otherwise, disable the timer in the beginning of the subroutine and enable it again at the end.
0
 
jbird090897Author Commented:
ok sounds good how do i do that code wise
0
 
percosolatorCommented:
easiest way to do it (and least elegant) would be to execute a shell command that pings the server, redirect that output into a file and parse the file for a "Request Timed Out" message, if not found, wipe the file and proceed to the next file.

"Ping 209.123.34.1 > C:\Replies.Txt"

Or, maybe someone else could tell you how to check using a more direct means.



0
 
jf26028Commented:
This is the code that they mentioned in the above comments:


Form1 contains:

Timer1
List1



'This is the code in the form:


Private Sub Timer1_Timer()
    Dim I As Integer    'counter variable
       
    List1.Clear         'erase the last responses
       
        'for all the machines, check to see if they are
        'responding
       
    For I = 1 To 5
        FindMachine Machines(I)
    Next
   
End Sub


'that is all for the form




'this is in a module with a sub main().  Sub main must
'be the startup object.  Set this by pressing alt + p and
'alt + e, the change the startup object from form1 to sub main

Option Explicit

'global array of computer names to ping
Global Machines(1 To 5) As String
   
Public Sub main()


    'populate the array with the computer names
    'you change each of these for your own use
    Machines(1) = "Computer1"
    Machines(2) = "Computer2"
    Machines(3) = "Computer3"
    Machines(4) = "Computer4"
    Machines(5) = "Computer5"
       
    Form1.Show
   
   
End Sub
   
   
Public Sub FindMachine(MachineName As String)
        'string used to search the output file
    Dim InString As String
        'temp long to hold response from Shell()
    Dim Temp As Long
   
        'this is the batch file you will shell
    Open "c:\temp\runthis.bat" For Output As #1
    Print #1, "ping " & MachineName & " > c:\temp\output.tmp"
        'eof.tmp is a temp file used to know when the ping process is done
    Print #1, "del c:\temp\eof.tmp"
    Close #1
   
        'copy the temp file to delete later
    FileCopy "c:\temp\runthis.bat", "c:\temp\eof.tmp"
        'shell the ping
    Temp = Shell("c:\temp\runthis.bat", vbHide)
        'wait until the process if finished
    While Dir("c:\temp\eof.tmp") <> ""
        DoEvents
    Wend
        'parse the file
    Open "c:\temp\output.tmp" For Input As #1
    While Not EOF(1)
        Line Input #1, InString
            'if reply is in the file, then the machine responded
        If InStr(InString, "Reply") Then
            Form1.List1.AddItem "Machine " & MachineName & " Online"
            Close #1
                'response found, exit
            Exit Sub
        End If
    Wend
        'if "reply" not found in the file, then the machine did not
        'respond and is offline
    Close #1
    Form1.List1.AddItem "Machine " & MachineName & " Offline"
End Sub



'end of code.

You need to set Timer1.Interval to whatever you want the interval
between checking the computers to be.

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now