Module Module1
Sub Main()
Dim Ping As New System.Net.NetworkInformation.Ping
Dim PingList As New List(Of String)
'' Add all addresses you want to ping. This will only work for computers inside your network. Not online.
PingList.Add("10.10.10.1")
PingList.Add("10.10.10.2")
PingList.Add("10.10.10.3")
PingList.Add("localhost")
'' Set where you want to save here!
Dim OutputPath As String = "C:\PingOut.txt"
'' Set how often you want to ping (default 15 minutes)
Dim PingFrequency As New TimeSpan(0, 15, 0)
'' This part will write to the file. Press any key to end this and save the file.
Dim Output As New IO.StreamWriter(OutputPath, True)
Console.WriteLine("Saving to " & OutputPath)
Dim ToOutput As String = String.Format("{0}|{1}|{2}|{3}", _
FormatString(13, "Time of ping"), _
FormatString(13, "Address"), _
FormatString(13, "Time (ms)"), _
"Status")
Output.WriteLine(ToOutput)
Console.WriteLine(ToOutput)
Output.WriteLine("{0}|{0}|{0}|{0}", FormatString(13, "", "-"))
Console.WriteLine("{0}|{0}|{0}|{0}", FormatString(13, "", "-"))
Dim LastTime As Date = Now - PingFrequency - New TimeSpan(0, 1, 0)
Do
If Console.KeyAvailable Then Exit Do
If Now - PingFrequency < LastTime Then Continue Do
For Each Address As String In PingList
Dim Result As Net.NetworkInformation.PingReply = Ping.Send(Address)
ToOutput = String.Format("{0}|{1}|{2}|{3}", _
FormatString(13, Now.Hour & ":" & Now.Minute & ":" & Now.Second), _
FormatString(13, Result.Address.ToString), _
FormatString(13, Result.RoundtripTime), _
FormatString(13, Result.Status.ToString))
Console.WriteLine(ToOutput)
Output.WriteLine(ToOutput)
Next
Output.WriteLine("{0}|{0}|{0}|{0}", FormatString(13, "", "-"))
Console.WriteLine("{0}|{0}|{0}|{0}", FormatString(13, "", "-"))
LastTime = Now
Loop
Output.Close()
End Sub
Function FormatString(ByVal Count As Integer, ByVal Text As String, Optional ByVal Formater As Char = " ") As String
For X As Integer = Text.Length To Count
Text &= Formater
Next
Return Text
End Function
End Module