Batch script to Check internet availability and renew adapter(s) if doesn’t exist


Scenario:

My PC is on 24 x 7 x 365 & I am a huge downloader. Of late, my internet connection gets disconnected after a while and I have to ipconfig /release and ipconfig /renew to resume my torrents. I wanted to automate this. So, with a little bit of help from google, I figured this out.

Solution:
create a file r_r.bat in %systemroot% with the following contents

@echo off
ipconfig /release *Hath*
echo
echo The IP address has been released. Waiting to renew…
echo waiting for a minute
ping xyz.boogvgd.bam -w 5000>NUL
echo
ipconfig /renew *Hath*
echo The IP address has been renewed

Here, replace *Hath* with you connection name. For ex. if you internet connection name is “Local Area Connection 1”, you could use *Local Area* OR *Connection 1* etc.
Now create another file chk_sts.bat in %systemroot% with the following contents.

ping -n 1 http://www.google.com > NULL
if errorlevel 1 r_r.bat

Save both the files.

Now go to Start–>Settings–>Control Panel –>Scheduled Tasks –>Add Scheduled Tasks.
Add a new task which will repeat itself every 10 minutes(the timing is upto you) using the chk_sts.bat file as the executable. Voila!!

Incase anyone wants to know the details, leave a comment and i’ll try my best.

-J

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s