Parsing a Ping. If over or under a ms..

February 12, 2011 at 01:12:29
Specs: Windows 7, 4GB RAM.
Wasnt sure what to say on the title.

SO, look at this:
set b=0
For /F "Tokens=3" %%I in ('ping www.google.com -n 1') Do Set CHK=%%I
if "%CHK%" LSS "15ms," set /a b=%b%+1
if "%CHK%" LSS "30ms," set /a b=%b%+1
if "%CHK%" LSS "50ms," set /a b=%b%+1
if "%CHK%" LSS "99ms," set /a b=%b%+1
if "%CHK%" LSS "120ms" set /a b=%b%+1
if "%CHK%" LSS "200ms" set /a b=%b%+1
if "%CHK%" LSS "300ms" set /a b=%b%+1
if "%CHK%" LSS "600ms" set /a b=%b%+1
if "%CHK%" GTR "12000ms" set /a b=%b%+1
If %b%==1 set Statis=Very Very good
If %b%==2 set Statis=Very good
If %b%==3 set Statis=Good
If %b%==4 set Statis=Normal.^(Maybe laggy^)
If %b%==5 set Statis=Bad
If %b%==6 set Statis=Very bad
If %b%==7 set Statis=Very very bad
If %b%==7 set Statis=So bad, consider yourself offline.
If %b%==8 set Statis=Hella bad.
Echo Internet Status: %statis%

How this is SUPPOSED to work.
If a ping is less then 15, 30, etc, itll add a number. So if the ping is say...35, itll pass 15 and 30, add a number(2) and not pass any more.
Then itll say a status message depending on how many numbers accumulated up.
I also have tried to write a script thatll automagically ipconfig /release and ipconfig /renew because this is for a laptop, and magically renewing the internet will boost speed it up again for a while.
thats irrelevent though, itll work fine if this works.

My problem is, it wont do a CURRECT gtr or lss check if the ms if over 99.

For example.
The script above. Itll acount the 120ms as 20ms.
It hates triple digets, I dont know why.
I tried to add " " to them, take them out, do things, yet I dont know what im doing wrong.
Any assistance would be very very nice.


See More: Parsing a Ping. If over or under a ms..

Report •


#1
February 12, 2011 at 01:40:43
I suggest stripping out the "ms", it will make the number comparison much easier:

For /F "Tokens=4 delims=m " %%I in ('ping www.google.com -n 1') Do Set CHK=%%I

You will also need to remove the double quotes to change from a string compare to an int compare:

if %CHK% LSS 15 set /a b=%b%+1


Report •

#2
February 12, 2011 at 01:52:14
Also I think you may have you logic mixed up:

For /F "Tokens=4 delims=m " %%I in ('ping www.google.com -n 1') Do Set CHK=%%I
set b=9

for %%a in (15 30 50 99 120 200 300 600 1200) do if %chk% lss %%a set /a b -= 1


If %b%==0 set Statis=Very Very good
If %b%==1 set Statis=Very good
If %b%==2 set Statis=Good
If %b%==3 set Statis=Normal.^(Maybe laggy^)
If %b%==4 set Statis=Bad
If %b%==5 set Statis=Very bad
If %b%==6 set Statis=Very very bad
If %b%==7 set Statis=So bad, consider yourself offline.
If %b% geq 8 set Statis=Hella bad.
Echo Internet Status: %statis%


Report •

#3
February 12, 2011 at 01:53:22
Oh neat, I didnt know I could chop off part of it that easily.
AND I didnt know it did a string compare. Hmm.

And it seems my problem is now fixed!
Thank you. I might post again if its not really fixed or something, but i am pretty sure it is. Thanks!

EDIT:
Didnt see the third post there.
For some reason the whole:
for %%a in (15 30 50 99 120 200 300 600 1200) do if %chk% lss %%a set /a b -= 1

confuses me.
I used GTR's instead of LSS's though because its easier that way. I guess both work but its more understandable.

I will have to analyze your little line so I can understand it though, seems alot 'cleaner' then how I was doing it lol.
Im not used to using the FOR command yet..


Report •

Related Solutions

#4
February 12, 2011 at 02:18:07
That's probably the simplest for command you will come across, each number gets passed to the "do" part inside %%a.

I simply set %b% to the worst possible and decremented it each time it was less than one of the selected numbers.

I just realised that I messed up the logic a little anyway by including "1200".

For /F "Tokens=4 delims=m " %%I in ('ping www.google.com -n 1') Do Set CHK=%%I
set b=9


for %%a in (15 30 50 99 120 200 300 600) do if %chk% lss %%a set /a b -= 1


If %b%==1 set Statis=Very Very good
If %b%==2 set Statis=Very good
If %b%==3 set Statis=Good
If %b%==4 set Statis=Normal.^(Maybe laggy^)
If %b%==5 set Statis=Bad
If %b%==6 set Statis=Very bad
If %b%==7 set Statis=Very very bad
If %b%==8 set Statis=So bad, consider yourself offline.
If %b%==9 set Statis=Hella bad.
Echo Internet Status: %statis%
pause


Report •


Ask Question