Create a batch file that will log the time & date of your internet disconnection or reconnection

Edited by Adrian Penaflor, Charmed, Anonymous, Doug Collins and 6 others

If you have sporadic internet connection and you want to automatically log the instances of your disconnection and reconnection, then this article is for you. You do not need to buy or install a special software or program. All you need is a simple notepad to save the batch file codes and of course, a PC that is running all the time. When you run the batch file, it will do an infinite loop of continuous ping.

Was this helpful? Yes | No | I need help

I've added a sound feature but it only works with Windows XP. You will hear a (wav) sound if your internet connection went down or if your connection came up again. It will also log the time & date at the start or on disconnection/reconnection. All logs will be saved into one txt file.

Was this helpful? Yes | No | I need help

Ad

Instructions

1. Open your notepad and cut and paste the code below, then hit save.

@Echo off
cls
c:\windows\system32\mplay32 /play /close c:\Windows\media\tada.wav

echo T.BAT started at
time/t
echo T.BAT started at >> c:\log.txt
time/t >> c:\log.txt
date/t >> c:\log.txt
echo. >> c:\log.txt

:START
ping google.com
if errorlevel 1 (
c:\windows\system32\mplay32 /play /close c:\Windows\media\ding.wav
echo.
echo ------------OFFLINE------------
time/t
echo TIME OF DISCONNECTION >> c:\log.txt
time/t >> c:\log.txt
date/t >> c:\log.txt
echo. >> c:\log.txt
:NOTONLINE
ping google.com
if errorlevel 1 (
echo No Internet.
time/t
) else (
c:\windows\system32\mplay32 /play /close c:\Windows\media\tada.wav
echo.
echo ------------Now Online again------------
time/t
echo NOW ONLINE >> c:\log.txt
time/t >> c:\log.txt
date/t >> c:\log.txt
echo. >> c:\log.txt
GOTO START
)
GOTO NOTONLINE

Was this helpful? Yes | No | I need help

) else (
echo.
echo ------------Now Online------------
time/t

)
GOTO START

T.bat batch file.png

2. And then save it as T.BAT in the root C: drive. Please check the picture below:

Tba.png

3. Now run it by double-clicking the T.BAT in the root C: drive.
4. It should be pinging with replies if you are online.

Continous ping loop.PNG

5. You can always go to the root C: drive to check the logs. The filename

is log.txt.
Tbat.png
  • (Here is the content of the log.txt on the long run.)
    Connection logs.PNG

Tips Tricks & Warnings

  • The user can always stop the batch file by pressing Ctrl + C.
  • The sound will only work with Windows XP
  • You must run it as administrator if you are using Win7+

Was this helpful? Yes | No | I need help

Questions and Answers

I want to create a bat file that will keep record continuously ISP's pinging record with time and date every hour?

I want to create a bat file that will keep record continuously ISP's pinging record with time and date every hour

Create a pingtest.bat file with the code starting with "@ECHO OFF". You will be able to use the file by launching the Command Prompt and typing pingtest YourISPSite.com logfile Where "YourISPSite.com" can be replaced with a site, an IP address of your choice, your router address, or the ISP address, depending on whether you need to test the connection with the router, ISP, or with other sites; "logfile" is a name for a log TXT file in the same folder as pingtest.bat. Please make sure to keep the program running. It will write data to your log file every 24 hours. Terminate the program with Ctrl+C from the Command Prompt.

Was this helpful? Yes | No | I need help

@ECHO OFF
:LOOPED
echo %date% >> %2.txt
set time_hh=%time:~0,2%
if %time_hh% lss 10 (set time_hh=0%time:~1,1%)
set time_mn=%time:~3,2%
set time_ss=%time:~6,2%
set time_ms=%time:~9,2%
echo %time_hh%:%time_mn%:%time_ss%.%time_ms% >> %2.txt
ping %1 -n 1 >> %2.txt
echo. >> %2.txt
echo. >> %2.txt
timeout 86400
Go to LOOPED

Was this helpful? Yes | No | I need help

Continuous ping test batch file with date?

Continuous ping test batch file with date

Create a pingtest.bat file with the code starting with "@ECHO OFF". You will be able to use the file by launching the Command Prompt and typing pingtest Google.com logfile Where "Google.com" can be replaced with a site or IP address of your choice; "logfile" is a name for a log TXT file in the same folder as pingtest.bat. Terminate the program with Ctrl+C from the Command Prompt.

Was this helpful? Yes | No | I need help

@ECHO OFF
:LOOPED
echo %date% >> %2.txt
set time_hh=%time:~0,2%
if %time_hh% lss 10 (set time_hh=0%time:~1,1%)
set time_mn=%time:~3,2%
set time_ss=%time:~6,2%
set time_ms=%time:~9,2%
echo %time_hh%:%time_mn%:%time_ss%.%time_ms% >> %2.txt
ping %1 -n 1 >> %2.txt
echo. >> %2.txt
echo. >> %2.txt
Go to LOOPED

Was this helpful? Yes | No | I need help

Hi, how are you? Ping text file with time and date?

I would like to create a ping text file with time and date for checking which time my network is down or up. Please help

Create a pingtest.bat file with the code starting with "@ECHO OFF". You will be able to use the file by launching the Command Prompt and typing pingtest Yahoo.com logfile 0 Where "Yahoo.com" can be replaced with a site or IP address of your choice; "logfile" is a name for a TXT file for the logs in the same folder as pingtest.bat; "0" is the delay between each ping. "0" is no delay, "1" is one second, "2" is two seconds, etc. Terminate the program with Ctrl+C from the Command Prompt.

Was this helpful? Yes | No | I need help

@ECHO OFF
:LOOPED
echo %date% >> %2.txt
set time_hh=%time:~0,2%
if %time_hh% lss 10 (set time_hh=0%time:~1,1%)
set time_mn=%time:~3,2%
set time_ss=%time:~6,2%
set time_ms=%time:~9,2%
echo %time_hh%:%time_mn%:%time_ss%.%time_ms% >> %2.txt
ping %1 -n 1 >> %2.txt
echo. >> %2.txt
echo. >> %2.txt
timeout %3 > NUL
Go to LOOPED

Was this helpful? Yes | No | I need help

I need to take log sheet of daily network status?

I need to take log sheet of daily network status. I have tried: Nothing. I think it was caused by: Nothing

VisiHow QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.

How to create batch file for continuos ping status?

How to create batch file for continuos ping status

VisiHow QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.

Comments

VisiHow welcomes all comments. If you do not want to be anonymous, register or log in. It is free.




Keystone2
Featured Author
13 Articles Started
593 Article Edits
14,430 Points
Keystone2 is a featured author with VisiHow. Keystone2 has achieved the level of "Gunnery Sergeant" with 14,430 points. Keystone2 has started 13 articles (including this one) and has also made 593 article edits. 1,964,000 people have read Keystone2's article contributions.
Keystone2's Message Board
Keystone2: Hi, my name is Keystone2.
Keystone2: Can I help you with your problem about "Create a batch file that will log the time & date of your internet disconnection or reconnection"?
 

Article Info

Categories : Programming

Recent edits by: Jen M, waqar, safridi_82

Share this Article:

Thanks to all authors for creating a page that has been read 7,923 times.

Do you have a question not answered in this article?
Click here to ask one of the writers of this article
x

Thank Our Volunteer Authors.

Would you like to give back to the community by fixing a spelling mistake? Yes | No