1.

Solve : [Batch] Ping Script??

Answer»

It is possible to make something LIKE this ...
Code: [Select]@ECHO OFF
Title Service Check
CD\
CLS

Rem Step 1:
Ping 95.76.53.219
echo Your connection to the 95.76.53.219 is %ms%
Pause

I want to show only the average in Ms with that echo ?...

it is possible ? ping_avg.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
set count=0
set total=0
for /F "tokens=3,7 delims==: " %%G in ('ping yahoo.com ^| findstr /C:"Reply from"') do (
set /a count+=1
SET ms=%%H
set ms=!ms:ms=!
set /a total=!total! + !ms!
)
set /a average=%total% / %count%
echo Your connection to Yahoo.com is %average%msnot working (

the console remain blank ....

@ Windows 7 UltimateQuote from: CaTaLinU on May 09, 2012, 10:11:55 AM

not working (

Fine here...

Code: [Select]C:\Batch\Test>aveping.bat
Your connection to Yahoo.com is 188ms

C:\Batch\Test>


Windows 7 Professional
Quote from: CaTaLinU on May 09, 2012, 10:11:55 AM
not working (

the console remain blank ....

@ Windows 7 Ultimate
Don't know what to tell you. Works just fine for me.
Code: [Select]C:\batch files>ping_avg.bat
Your connection to Yahoo.com is 49ms( F**king windows .........

Someoen knows from what is this "error"
For Salmon Trout worked this script but for me the console remain blank...Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line...

C:\Batch\Test>ping www.yahoo.com

Pinging eu-fp3.wa1.b.yahoo.com [87.248.122.122] with 32 bytes of data:
Reply from 87.248.122.122: bytes=32 TIME=52ms TTL=52
Reply from 87.248.122.122: bytes=32 time=51ms TTL=52
Reply from 87.248.122.122: bytes=32 time=75ms TTL=52
Reply from 87.248.122.122: bytes=32 time=50ms TTL=52

Ping statistics for 87.248.122.122:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round TRIP times in milli-seconds:
Minimum = 50ms, MAXIMUM = 75ms, Average = 57ms


easy enough...

for /f "tokens=1-9" %%A in ('ping www.yahoo.com ^| find "Average ="') do echo Average=%%I
Quote from: CaTaLinU on May 09, 2012, 10:52:39 AM
For Salmon Trout worked this script but for me the console remain blank...

It worked for Squashman too.

1. Please don't use bad language, even censored.
2. How are you running this code?

Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..Quote from: Salmon Trout on May 09, 2012, 10:53:43 AM
Maybe he doesn't want to do batch arithmetic; perhaps he just wants to isolate the average part of the ping output summary line...

C:\Batch\Test>ping www.yahoo.com

Pinging eu-fp3.wa1.b.yahoo.com [87.248.122.122] with 32 bytes of data:
Reply from 87.248.122.122: bytes=32 time=52ms TTL=52
Reply from 87.248.122.122: bytes=32 time=51ms TTL=52
Reply from 87.248.122.122: bytes=32 time=75ms TTL=52
Reply from 87.248.122.122: bytes=32 time=50ms TTL=52

Ping statistics for 87.248.122.122:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 50ms, Maximum = 75ms, Average = 57ms


easy enough...

for /f "tokens=1-9" %%A in ('ping www.yahoo.com ^| find "Average ="') do echo Average=%%I
That makes the code a lot easier. Not sure why I didn't do that in the first place.Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM
Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..

Sounds about right, mine took nearly 23 seconds. Maybe you have a slow connection?


C:\Batch\Test>(
More? echo %time%
More? aveping.bat
More? echo %time%
More? )
18:18:24.61
Your connection to Yahoo.com is 158ms
18:18:47.23

Quote from: CaTaLinU on May 09, 2012, 11:01:27 AM
Bat File Name - ping.bat

code given by Squashman is not changed, i run it how he give it to me

the Double-Click on ping.bat
if i wait more than 30 sec my pc it will work very slowly ..
Well there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!!Quote from: Squashman on May 09, 2012, 11:21:17 AM
Well there is your mistake. You can't name your batch file the same as a command in your batch file!!!!!!!

I missed that... I just assumed nobody would ever call a batch script ping.bat...
Quote from: Salmon Trout on May 09, 2012, 11:24:40 AM
I missed that... I just assumed nobody would ever call a batch script ping.bat...

Now works fine

Thx a lot Quote from: CaTaLinU on May 09, 2012, 11:29:27 AM
Now works fine

Thx a lot
Would probably run a tad faster if you used Salmon Trout's code.


Discussion

No Comment Found