Guide Intenet Connectivity Check and Reconnection via Batch File.

Status
Not open for further replies.
Hi

Here is a Batch(.bat) file which will automatically check for network/internet connectivity and if not found will automatically reconnect. This is will come in very handy for people who's internet link keeps dropping and are having frequent disconnections. This is a customized code which I use(pppoe on PC). Go to the source (see ref.) for original code and customize as per your requirement.

I'm not checking for DNS errors cuz It was resulting in error, also i dont usually face dns issues.

Replace ConnectionName with the name of your Broadband Dialer
USERNAME with username and
PASSWORD with password.

Note: This is aimed@ people who dial (pppoe) on the PC and Reconnection part will only for such people. Will not work if you dial(pppoe) on modem or router.

For people with router, put your router on always on mode so whenever the line drops it will automatically reconnect. And for people which do PPPoE on modem, I think it's about time you put it on bridged mode.

A) Copy this code.
B) Open notepad and paste.
C) Customize.
D) Save as xxxx.bat or xxxx.cmd and Schedule
E) Enjoy non-stop torrent downloading :hap2:

Code:
@echo off
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF     ERRORLEVEL 1 goto :TRYAGAIN

:TRYAGAIN
ECHO -------------------------------------------------------        
ECHO -------------------------------------------------------
ECHO FAILURE!
ECHO Let me try a bit more, please wait...
@echo off
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS2
IF     ERRORLEVEL 1 goto :FAILURE

:SUCCESS
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active Internet connection
pause
goto END

:SUCCESS2
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active internet connection but some packet loss was detected.
pause
goto :END

:FAILURE
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You do not have an active Internet connection
ECHO Reconnecting.. Please Wait
ECHO -------------------------------------------------------   
ECHO -------------------------------------------------------
@echo off
rasdial ConnectionName /DISCONNECT
rasdial ConnectionName USERNAME PASSWORD
ECHO Re-checking Connection, please wait...
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF     ERRORLEVEL 1 goto :FAILURE2

:FAILURE2
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO Reconnenction Failed.
ECHO Please try later.
pause
goto :END

:END

You can Schedule this to run every 15min - 30mins to check for connectivity.
Feel free to pop a question.

For people using router, if this doesn't help you then try using AHK(Auto Hot Key) or Imacro's for firefox for automation. Can draw inspiration from here http://www.techenclave.com/guides-and-tutorials/guide-night-downloading-mtnl-749nu-plan-113072.html

Njoy.
 
Doesn't PPOE automatically takes care of reconnecting if the line is dropped? There is an option when you create this connection in Windows, isn't it?

Under redialing properties we have a checkbox saying 'Redial if line is dropped'
 
Its happens quite often, well atleast with me that although the line isn't dropped yet the net doesn't work, so then this thing comes in handy.

Also this thing is more versatile and flexible, you can put in anything you want.
for example check for internet connectivity, if found true then start download manager or utorrent, if not then connect and then start the app.
 
will it work when pc restarts suddely and there is no connection found after startup, will it connect automatically on it's own whenever a connection is not present.
 
Status
Not open for further replies.