Solved

Network Down?

Posted on 1998-08-01
4
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

623 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