?
Solved

Sending ping requests in vb5

Posted on 2003-03-31
4
Medium Priority
?
206 Views
Last Modified: 2010-04-07
Im trying to write a program that at regular intervals pings a server/ip address and tells the user whether or not the server is available i'm trying to set it up for my home network so i can tell which computers are online. The only thing I am stuck on is how to send ping requests and read the results so that it will display a message when its online eg "Online" or when its offline "Unavailable." Can anyone help? Thanks
0
Comment
Question by:LordsOfChaos
[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
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 200 total points
ID: 8241691
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8241705
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8241815
you could also use the command interpretor to ping an address and redirect the results to a temp file.Then you can use the temp file in a function like so:


Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Function IsIpAlive(IpAddress As String) As Boolean
Dim hProcess As Long, RetVal As Long, ff As Integer, Ln As String
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, _
    Shell("command.com /c ping " & IpAddress & " > C:\ping.tmp", vbHide))
Do
    GetExitCodeProcess hProcess, RetVal
    DoEvents: Sleep 100
Loop While RetVal = STILL_ACTIVE
ff = FreeFile
Open "C:\ping.tmp" For Input As #ff
Do Until EOF(ff)
Line Input #ff, Ln
If InStr(1, Ln, "Reply from") > 0 Then
    IsIpAlive = True
    Close #ff
    Kill "C:\ping.tmp"
    Exit Function
End If
Loop
IsIpAlive = False
Close #ff
Kill "C:\ping.tmp"
End Function

Private Sub Command1_Click()
MsgBox IsIpAlive("127.0.0.1")
End Sub
0
 

Author Comment

by:LordsOfChaos
ID: 8241822
thank you that was very helpful and ive now completed my program
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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