I've been dabbling with Python tonight so I wrote a Python script to do this. To run it:
1) Install Python if you don't already have it (
https://www.python.org/downloads/)
2) Copy the below script to a text file and save it somewhere as
networkcheck.py
3) To run it, open a command prompt, change the directory to wherever you saved networkcheck.py and the type
py networkcheck.py
It will check the state of the network connection evey 60 seconds (you can change this period to a different amount by changing the waittime variable in the script). It will log the results to c:\logs\networkcheck.txt. You'll need to either create the c:\logs directory or change the script to write to a different directory. Just CTRL-C to stop it.
Code:
import datetime
import os
import time
filename = "c:\\logs\\networkcheck.txt" # Output log file name
hostname = "www.google.co.uk" # Host name or ip address to ping
waittime = 60 # Waits 60 seconds between checks
lastresponse = 1;
response = 0;
file = open(filename, "w")
while True:
response = os.system("ping -n 1 " + hostname + " > nul")
if response != lastresponse:
if response == 0:
status = "Connected"
else:
status = "No network connection"
logmessage = "[" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "] " + status + "\n"
file.write(logmessage)
file.flush()
lastresponse = response
time.sleep(waittime)
It will write a "Connected" or "No network connection" message every time the network connection is lost or reconnects. It won't log messages if the status stays the same (e.g. it won' continually log messages every minute - it will only log them if the status changes).
Sample output:
Code:
[2017-12-18 00:32:36] Connected
[2017-12-18 00:35:36] No network connection
[2017-12-18 00:36:36] Connected