Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Im not quit sure whats wrong with this code. please help.. its supposed to ping google and if no reply it supposed to exit the internet connection "pppoe" then restart the connection again.. Need this due to unreliable internet connection. thanks
@ECHO OFF :Game PING www.google.com |FIND "Reply from " > NUL IF NOT ERRORLEVEL 1 ECHO Internet connection is reciving packets boss. IF ERRORLEVEL 1 rasdial dsl /disconnect GOTO:protocol :protocol PING www.google.com cd "%ProgramFiles%\DSL" && START dsl" GOTO:Game

How about a hint. What is it doing? Or saying?
=====================================
If at first you don't succeed, you're about average.M2

Hing ok.. ehehe.
The batch file is supposed to run constantly in my task bar pining www.google.com When google doesn't reply its supposed to end my current connection because the connection has dropped. After ending the connection the batch file is supposed to Restart the connection (happens to be a pppoe connection)
THanks

Put pauses after each line, and see where it fails.
There are no stupid questions, just stupid people.

Get rid of "|FIND "Reply from " > NUL" in the ping line. You can
check the errorlevel after pinging google, to see if it succeeded.Like:
@echo off
ping google.com
if %errorlevel% neq 0 echo ERROR! && pauseThere are no stupid questions, just stupid people.

Perhaps you don't want to start dsl(whatever that is) if the connection is active?
IF NOT ERRORLEVEL 1 ( ECHO Internet connection is reciving packets boss. goto game )The goto :protocall seems to be worthless unless this is a condensed version of the code.

"Get rid of "|FIND "Reply from " > NUL" in the ping line. You can
check the errorlevel after pinging google, to see if it succeeded."Not quite.
As yet, we don't know what the malfunction is.
While we're at it, not much point in GOingTO the very next line. LOL
"GOTO:protocol
:protocol"
=====================================
If at first you don't succeed, you're about average.M2

Hey thanks guys for all your help.. I figured this out by incorporating the rasdial function instead of having it run a shortcut.
here is what i came up with
@ECHO OFF Color 0A :Game PING www.google.com |FIND "Reply from " > NUL IF NOT ERRORLEVEL 1 ECHO Internet connection is reciving packets Connection functional! IF ERRORLEVEL 1 ECHO PACKETS NOT BEING RECIEVED & rasdial dsl /disconnect & rasdial Connection name Username Password GOTO:Game
This works perfectly. If you could help me with one more thing. I would like to make this faster. I don't know how because it waits for the ping reply. If you know another method of checking the status of the connection, and if the batch finds The connection has dropped it would disconnect the connection and reconnect it again. I Just need to speed up the process of it detecting no connection so it can get my connection back up and running faster.THanks for any help guys.
ALex

ping google.com -n 1 -l 1 -w 100
Will ping only once, with only 1 byte of data ,with a timeout of 1/10 of a second if it fails (making it quicker to find if there was an error; change it to be slower or faster depending on your connection speed) which should make
it much quicker.What I was saying m2go, is that he doesn't need to find "reply from", he just needs to find if there was an error after attempting to ping google. This works perfectly, I tested it.
@echo off
:ping
ping google.com -n 1 -l 1 -w 100
if %errorlevel% equ 1 (echo Disconnected && pause) else (echo Connected)
goto pingThere are no stupid questions, just stupid people.

excuse me sir. if you are familiar with the rasdial command. Usually you use the rasdial command with the connection name, user-name, password fallowing the command. i was wondering if there is a way for the batch file to receive the required details (connection name, user-name, password) from a txt file that's in the same folder?
THank you

The text file must be in the same folder as the batch file, and
the information should be as follows:
Connection name
username
password
Save it as rasdial.txtHere is the script
for /F "tokens=* delims=<enter>" %%a in (%~dp0\rasdial.txt)
do (
set skip=f
for %%b in ("cn" "un" "pw") do (
if "!skip!" == "f" (
if not defined %%~b (
set skip=t
set %%~b=%%a))))**ALL THE OTHER CODE HERE**
IMPORTANT
The rasdial command should look like:
rasdial %cn% %un% %pw%There are no stupid questions, just stupid people.

Sorry sir but i don't quite understand how to incorporate your code into my batch
Here is my code if you would be so kind to help me understand how to incorporate your code into mine
@ECHO OFF Color 0A :Game PING www.google.com |FIND "Reply from " > NUL IF NOT ERRORLEVEL 1 ECHO Internet connection is reciving packets Connection functional! IF ERRORLEVEL 1 ECHO PACKETS NOT BEING RECIEVED & rasdial dsl /disconnect & rasdial ConnectionName UserName Password GOTO:GameI am also in the process of incorporating your tip that u explained above about the 1 byte ping with a short timeout.
Thanks so much. You have already helped a ton
ALex

Try this
@ECHO OFF
Color 0Afor /F "tokens=* delims=<enter>" %%a in (%~dp0\rasdial.txt)
do (
set skip=f
for %%b in ("cn" "un" "pw") do (
if "!skip!" == "f" (
if not defined %%~b (
set skip=t
set %%~b=%%a)))):Game
ping google.com -n 1 -l 1 -w 100
IF ERRORLEVEL 0 ECHO Internet connection is reciving packets Connection functional!
IF NOT ERRORLEVEL 0 ECHO PACKETS NOT BEING RECIEVED & rasdial dsl /disconnect & rasdial %cn% %un% %pw%
GOTO:GameThere are no stupid questions, just stupid people.

Yes sir i tried it. The thing is it doesnt do anything. It just flashed the cmd prompt then closed again. Any ideas?
THanks againALex

@echo off
setlocal enabledelayedexpansion
for /F "tokens=* delims=<enter>" %%a in (rasdial.txt) do (
set skip=f
for %%b in ("cn" "un" "pw") do (
if "!skip!" == "f" (
if not defined %%~b (
set skip=t
set %%~b=%%a)))):loop
ping google.com -n 1 -l 1 -w 100
if !errorlevel! equ 0 (echo Internet connection is reciving packets, Connection functional!) else (echo PACKETS NOT BEING RECIEVED && rasdial dsl /disconnect & rasdial %cn% %un% %pw%)
goto loopThere are no stupid questions, just stupid people.

Sorry bro for the inconvenience. Most of the code is working. I can observe when it gets to the rasdial command its not running rasdial to restart the the "pppoe" connection. Im not sure if it is ending the connection but it doesn't matter because its using the "&" NOT the "&&" here is the screen shot to help out a little bit.. thanks for helping out.
Batch file and rasdial.txt are both on desktop. thankshttp://img252.imageshack.us/img252/...
ALex

Rename you script, naming script after a command(especially one that is used in the script) can cause many problems.
Open a cmd window an type in "set path" you should get two variables displayed(there may be more) "path" and "pathext".A good deal of commands tend to be external (i.e they are actually .exe's, .com's, ect.), rasdial is one of them. when an external command is called first the cmd processor looks in the current directory, then each of the semicolon delimted directories are checked.
These directories are checked for the command name with the pathext file extensions, in the order they are listed as soon as it finds a match it calls it and quits.
In your case of "rasdial.bat" something like this happens.(
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\WbemPATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
)rasdial.bat rasdial?
cmd: it's not built into me, I'll look for it!
cmd: First I'll start with the current directory,
cmd then go over the path directories.
cmd: Checking the current directory for:
rasdial.com...NO
rasdial.exe....NO
rasdial.bat.....YES!!!!
cmd: run rasdial.bat
cmd: I found rasdial so I'll stop looking.Of course after which rasdial.bat asks for rasdial again, hence the setlocal recursions.

WOw Judago You nailed it right on the head my friend.. thanks alot for that.. had me stumped for a few hours.. U noticed it right off the top of the notepad doc. wow.. nice eye.
Now with the code that was so nicely given to me by xterm11
It is not getting the code from the txt document or its reading the txt document incorectly. hese a screen shot. If someone could kindly help me.. this is the final error
http://img300.imageshack.us/img300/...THanks Judago and xterm11.
Any ideas?
ALex

OK OK i figured it out. Thanks so much xterm11 couldn't have done it without you bud. That helps so much. i thought the rasdial.txt had to be like this
connectionName
Username
Passwordwhen i tried it like this=
connectionName Username Password << IT WORKED
Thanks alot xterm11 helped a TON
And Judago w/out you i wuda been stuck and nvr changed the name of the freakin batch file. Thanks dude!!!! IT works PERFECTLY thanks to u guys... no bugs at all thanks guys.!!

[edit]
Posted after the problem was fixed!
[edit]
xterm11 wrote.
"Connection name
username
password
Save it as rasdial.txt
"I'm a little bit lazier about it, it would be soooo much easier to put all of these things on one line, delimited by something like a tab, then run a for loop over it.
Here is my interpretation:
<untested>
@echo off setlocal enabledelayedexpansion ::rasinfo.txt :: one line :: <connection name><tab><username><tab><password> :: Nothing else!! for /F "tokens=1-3 delims= " %%a in (rasinfo.txt) do ( set ras_connect=%%a set ras_user=%%b set ras_pass=%%c ) :loop > nul ping google.com -n 1 if not errorlevel 1 ( echo Internet connection is reciving packets, Connection functional^^! ) else ( >nul ping google.com -n 3 if not errorlevel 1 ( echo PACKETS NOT BEING RECIEVED rasdial %ras_connect% /disconnect rasdial %ras_connect% %ras_user% %ras_pass% ) ) ::The below ping it for a time out perion :: works on xp, if it doesn't work on vista :: use "localhost" instead. :: a sleep function would be better.... >nul ping 0.0.0.0 -n 60 goto loopYou can change the delimiter to something other than a tab if you like....

Like I said about 14 replies back, you need to FIND "Reply".
=====================================
If at first you don't succeed, you're about average.M2

Wow thats a good looking code. Looks like its very efficient,
The problem im having with your code judago is when i simulate a disconnection "removing the telephone cord" from the modem or disconnecting the connection from task tray it doesn't reconnect the connection
screen shot: http://img39.imageshack.us/img39/61...
would be nice to get your code working for me.
Thanks
ALex

"Like I said about 14 replies back, you need to FIND "Reply".
@M2
Isn't that just an issue with the win 2000 ping if the host refuses the ping(i.e. not an issue on the target of xp)?
The problem im having with your code judago is when i simulate a disconnection "removing the telephone cord" from the modem or disconnecting the connection from task tray it doesn't reconnect the connection.How long did you give it? The "ping 0.0.0.0 -n 60" causes a time out for roughly 1 minute(59.044 seconds acording to ntimer on my machine) after each sucessful ping.
I tested the ping part but not the rasdial, my modem has a login client I don't really want to screw with.... Unpluging the cable caused bad pings(after the timeout elapsed) for me pluging it back a caused pings to suceed again.

Well i have just disconnected the connection so its impossible for a ping reply, It doesn't echo packets not being recieved, doesn't progress to rasdial /disconnect or rasdial. so after it detects no ping reply it just stops. Whats your idea?
THanks
ALex

This line:
">nul ping 0.0.0.0 -n 60"
Was only meant to be a time out so that the script is not endlessly sucking down bytes, like I said it takes about a minute, try removing that line and try again.
M2 was completely correct and is vindicated, looking into it.

Yup removed that line and it sticks or stops at the same place. Erlyer i tried the same thing but i waited a good 3minutes for the delay function to resume the script but it didn't do anything either. It pings just fine but when it encounters no reply it doesn't do anything.
THanks for the reply
ALex

M2 is completely correct and vindicated, from another thread I though that it was only about win 2000 and pinging a host that refused, I guess I eat my words....
<Still fixing....

Hi Judago, it may be a 2K/XP issue. No XP here to try it with.
With 2K it will return 0 as long as it resolves name to IP, regardless of a reply.
=====================================
If at first you don't succeed, you're about average.M2

Hi M2, I don't know what to to believe anymore, it would be
nice to have more consistency..... Anyhow at least it isn't
completely ignored. I came to the conclusion a while ago
when you posted the address to you server, which (if I
remember correctly) was configured to cause the issue, my
errorlevel was one so I assumed that it was a 2k issue.
Guess it doesn't hurt any way.....I think I may found the *real* issue with this screwy batch, finding reply alone doesn't help.
This may not go for everyone but when I disconnect the phone line my modem starts replying to pings(even those addressed to google!).
Give this a whirl it *might* work this time.....
I left the timeout in but I moved it.
@echo off setlocal enabledelayedexpansion ::rasinfo.txt :: one line :: <connection name><tab><username><tab><password> :: Nothing else!! for /F "tokens=1-3 delims= " %%a in (rasinfo.txt) do ( set ras_connect=%%a set ras_user=%%b set ras_pass=%%c ) for /f "tokens=1* delims=:" %%a in ('ipconfig') do set exclude=%%b set exclude=%exclude:~1,-1% :loop ping google.com -n 1|find /v "%exclude%"|>nul find /i "reply" if not errorlevel 1 ( echo Internet connection is reciving packets, Connection functional^^! >nul ping 0.0.0.0 -n 60 ) else ( ping google.com -n 1|find /v /i "%exclude%"|>nul find /i "reply" if errorlevel 1 ( echo PACKETS NOT BEING RECIEVED rasdial %ras_connect% /disconnect rasdial %ras_connect% %ras_user% %ras_pass% ) ) goto loop

OMG wow its beautiful!! love it. Its like the Mona Lisa of batch files. hehe
THanks this is godlike. ok i set the ping delay to 1. can i get it to ping faster? If not its fine this works really well
THANK YOU SO MUCH Judago
ALex

" ok i set the ping delay to 1. can i get it to ping faster?"
You *can* set the ping timeout slower with "-w <number in miliseconds>"(like xterm11's does) just be careful set it high enough that it doesn't timeout when you download something, I believe the default is 300 miliseconds.

Ok thanks Judago. i Just left it at -n 1 when i use the -w which i did before asking you how to make the delay shorter -w makes it act weird. echo's me connection is functional but sometimes it just stops"pauses" then keeps going because indeed ping replys are being received.. i can conclude 1 sec is the bare minimum for this to run smoothly.. your help Judago and the help of xterm11 is greatly appreciated. thanks you very much.
THanks again
ALex

Yeah dont set timeout too low, Judago has a valid point when
it comes to downloading.M2Go, I really never knew that, I don't have any problems on
xp when checking errorlevel after pinging.So my script I supplied is now working, correct? We're just
trying to get Judago's to work?No matter how many times you go over a batch file, there will
almost always be an error you won't catch.There are no stupid questions, just stupid people.

Yup xterm11 your batch file is working well, using it to keep my connection alive actually. hehe.. thanks you guys.. both scripts work flawlessly. Thanks loads
ALex

"doesn't timeout when you download something"
hmm...
=====================================
If at first you don't succeed, you're about average.M2

Nope torrenting full blast and have a stable connection. I changed your -w to a -n 1 so it would leave a long enough delay b4 executing the disconnection. because it was getting a time out then disconnecting the connection reconnecting it then doing that over and over.. but with the -n 2 im monitoring it. so far stable connecting for over an hour while browsing the net and torrenting. Have any other advice?
THanks
ALex

It's great to see an application like this for a batch file.
There are no stupid questions, just stupid people.

![]() |
Copy a file to system32 f...
|
Script Help
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |