Solved

Network Down?

Posted on 1998-08-01
4
140 Views
Last Modified: 2010-05-03
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
Comment
Question by:jbird090897
4 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1467472
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
 

Author Comment

by:jbird090897
ID: 1467473
ok sounds good how do i do that code wise
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1467474
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
 
LVL 1

Accepted Solution

by:
jf26028 earned 100 total points
ID: 1467475
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now