Solved Ping List of Servers - Output Avg Response Time

August 2, 2016 at 14:40:03
Specs: Windows 7
I have rudimentary skills with batch files. I'm trying to find the fastest server within my VPN provider. So using a server.txt list of 15-20 servers like this:

I'm trying to get the "Average" round trip response time of each server output to a "results.txt" file.
This data is in the last line of ping results (Minimum = 21ms, Maximum = 25ms, Average = 23ms)

I have found many ping batch files but all of them are checking for connection status, or IP, or something other than response time. Any help would be aprecciated for this 60 year old guy!

message edited by AZMedia

See More: Ping List of Servers - Output Avg Response Time

Report •

August 2, 2016 at 22:18:11
✔ Best Answer
Basic framework:

@echo off & setlocal
for /f "tokens=*" %%a in (server.txt) do (
for /f "tokens=4 delims==" %%b in ('ping -a %%a^|find "Average"') do (
call :xx %%a %%b
:: output to file and put a sort about here.
sort speed
goto :eof

set x=%2
set x=%x:ms=%
set x=%x: =%
>> speed echo %x% %1

message edited by nbrane

Report •

August 3, 2016 at 20:12:47
If you want to go with something like PowerShell, you could do this
Get-Content server.txt
 ForEach-Object {
   $o = New-Object PSObject -prop @{ Name=$_; Time=$null }
   $t = (Test-Connection $_ -ErrorAction SilentlyContinue | 
         Measure-Object -Average ResponseTime).Average
   if ($t -ne $null) { $o.Time = $t }
   else              { $o.Time = 300000 }
 } |
 Sort-Object Time |
 Format-Table -AutoSize Name, Time |
 Out-File results.txt

How To Ask Questions The Smart Way

Report •

August 6, 2016 at 20:45:13
Razor2, thank you. I could not get Powersehell to work and spent half hour researching on permissions and stuff. This is why I wanted to use a .bat file, I have no experience with Powershell.

Report •

Related Solutions

August 18, 2016 at 05:52:53
Not entirely unexpected, since Microsoft managed to create a scripting environment that doesn't like running scripts. You can fix that by running PowerShell, and typing:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Then you just need to save the script as a .PS1 file, right-click, and select "Run with PowerShell."

The other option is to use VBScript:

If Not IsConsole Then _
  WScript.Quit CreateObject("WScript.Shell").Run( _
   "cscript " & WScript.ScriptFullName, 1, True _

Set FSO = CreateObject("Scripting.FileSystemObject")
Set WMI = GetObject("winmgmts:")
Set servers = CreateObject("ADODB.Recordset")
servers.Fields.Append "Server", 200, 255
servers.Fields.Append "time", 5

With FSO.OpenTextFile("servers.txt")
  Do Until .AtEndOfStream
    server = .ReadLine
    tme = 0
    WScript.StdOut.Write server
    For i = 1 To 4
      Set ping = WMI.Get("Win32_PingStatus.Address='" & server & "'")
      If ping.StatusCode = 0 Then
        tme = tme + ping.ResponseTime
        WScript.StdOut.Write ", " & ping.ResponseTime & "ms"
        tme = tme + ping.Timeout + 1
        WScript.StdOut.Write ", FAILED"
      End If
    Next 'i
    WScript.StdOut.WriteLine ""
    servers("Server") = server
    servers("time") = tme / 4
End With

servers.Sort = "time"
With FSO.OpenTextFile("output.txt", 2, True)
  Do Until servers.EOF
    .WriteLine servers("Server") & vbTab & servers("time")
End With

Function IsConsole()
  On Error Resume Next
  WScript.StdOut.WriteLine ""
  IsConsole = Not CBool(Err.Number)
End Function

How To Ask Questions The Smart Way

Report •

August 18, 2016 at 15:16:19
Thanks. I ended up using this. It works great for my purpose. I have 3 bat files like this, one for the LA, Vegas, and San Jose servers.

@echo off
for %%a in (
) do (
echo pinging %%a 1>&2
echo %%a
ping %%a -n 10 |find "Average ="

Report •

Ask Question