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

Edited by Adrian Penaflor, Charmed, Doug Collins, Monika 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 program or software. 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 a 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 goes down, or if your connection is good again. It will also log the time & date at the start of the disconnection, until the 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. 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+

Questions and Answers

I want to create a bat file that will keep records, 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

Was this helpful? Yes | No | I need help
  1. 1
    Create a pingtest.bat file with the code starting with "@ECHO OFF"
    .
    Advertisement
    Was this step helpful? Yes | No | I need help
  2. 2
    You will be able to use the file by launching the Command Prompt and typing
    Advertisement
    Was this step helpful? Yes | No | I need help

pingtest YourISPSite.com logfile

  1. 1
    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;
     
    1. "logfile" is a name for a log TXT file in the same folder as pingtest.bat.
    Was this step helpful? Yes | No | I need help
  2. 2
    Please make sure to keep the program running
    .
    It will write data to your log file every 24 hours.
    Was this step helpful? Yes | No | I need help
  3. 3
    Terminate the program with Ctrl+C from the Command Prompt
    .
    Was this step 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.

Can you help me create a 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.

  1. 1
    Create a pingtest.bat file with the code starting with "@ECHO OFF"
    .
    Was this step helpful? Yes | No | I need help
  2. 2
    You will be able to use the file by launching the Command Prompt and typing
    Was this step helpful? Yes | No | I need help

pingtest Yahoo.com logfile 0

  1. 1
    Where "Yahoo.com" can be replaced with a site or IP address of your choice;
    Was this step helpful? Yes | No | I need help

"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.

  1. 1
    Terminate the program with Ctrl+C from the Command Prompt
    .
    Was this step helpful? Yes | No | I need help
    Advertisement

@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 make a log sheet of daily network status.

I need to make a 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 continuous ping status?

How to create batch file for continuous ping status? Can you help?

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

Referencing this Article

If you need to reference this article in your work, you can copy-paste the following depending on your required format:

APA (American Psychological Association)
Create a batch file that will log the time & date of your internet disconnection or reconnection. (2017). In VisiHow. Retrieved Jun 24, 2017, from http://visihow.com/Create_a_batch_file_that_will_log_the_time_%26_date_of_your_internet_disconnection_or_reconnection

Was this helpful? Yes | No | I need help

MLA (Modern Language Association) "Create a batch file that will log the time & date of your internet disconnection or reconnection." VisiHow, visihow.com/Create_a_batch_file_that_will_log_the_time_%26_date_of_your_internet_disconnection_or_reconnection Accessed 24 Jun 2017.

Was this helpful? Yes | No | I need help

Chicago / Turabian VisiHow.com. "Create a batch file that will log the time & date of your internet disconnection or reconnection." Accessed Jun 24, 2017. http://visihow.com/Create_a_batch_file_that_will_log_the_time_%26_date_of_your_internet_disconnection_or_reconnection.

Was this helpful? Yes | No | I need help

If you have problems with any of the steps in this article, please ask a question for more help, or post in the comments section below.

Comments

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

Article Info

Categories : Programming

Recent edits by: ganesan, Jen M, waqar

Share this Article:

Thanks to all authors for creating a page that has been read 8,622 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