Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Sending ping requests in vb5

Posted on 2003-03-31
Medium Priority
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
Question by:LordsOfChaos
  • 3
LVL 28

Accepted Solution

vinnyd79 earned 200 total points
ID: 8241691
LVL 28

Expert Comment

ID: 8241705
LVL 28

Expert Comment

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

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))
    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
IsIpAlive = False
Close #ff
Kill "C:\ping.tmp"
End Function

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

Author Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

581 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