Solved

How can I monitor and log internet connectivity?

Posted on 2014-12-03
18
119 Views
Last Modified: 2014-12-10
I would like to monitor internet connectivity, since I suspect that the internet is cutting out thus causing online backup jobs to fail.
Apart from checking server logs etc, is there a script or a free program which would allow me to check for continuous internet connectivity, and log it, so I can look back to see if there was an interruption of some sort?
A log is necessary to look back on, and perhaps any other information the log can provide me which could help me determine if there was an interruption.
0
Comment
Question by:100questions
  • 8
  • 5
  • 2
  • +2
18 Comments
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
Simplest for now, is just use this:

ping server -t > pinglog.txt

This is the most basic thing to check, and checks if internet connectivity stays up and running.
You could make a more fancy one (with date/time stamp) if necessary.

Of course this might not be enough, as many things can fail (maybe the server stays online, but only the service goes down). But that's for later. First try this.

No time-outs > service was down, not the internet
time-outs > somewhere, connectivity was interrupted, Question is of course, where ? Local server, switch, router, internet provider, or remote server. Therefore, more pings are required, to every single node I just mentioned.

As you can see, a lot more work is waiting.
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
For some years now I've replaced ping with hrping for 2 simple reasons: included timestamps and a graphical view.

HTH,
Dan
0
 

Author Comment

by:100questions
Comment Utility
@Kimputer - thanks.  Is there a way to include a time stamp?
0
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
Easiest, is to use the tip above.

hrping -T -t server_ip > pinglog.txt
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Here's a small batch I use for continuous ping; it uses sleep.exe from http://www.microsoft.com/en-us/download/details.aspx?id=17657 (no need to install the ResKit if you have 7-Zip - just unpack rktools.msi, then unpack sleep.exe from rktools.msi and put it into the script's folder). An alternative is to replace line 28 with "ping.exe -n 2 localhost >NUL".
The script only logs status changes, so only the times when the connection drops and when it comes back.
@echo off
setlocal
mode con cols=40 lines=25
if "%~1"=="" (
	set /p IP=Name oder IP: 
) else (
	set IP=%~1
)
title Ping %IP%
set LogFile=%~dpn0-%IP%.log
set Lost=X
:loop
ping.exe -n 1 %IP% | find /i "TTL" >NUL
if errorlevel 1 (
	if not %Lost%==1 (
		color 4F
		echo - Down: %Date% %Time: =0%
		>>"%LogFile%" echo - %Date% %Time%
		set Lost=1
	) 
) else (
	if not %Lost%==0 (
		color 2F
		echo + Up: %Date% %Time: =0%
		>>"%LogFile%" echo + %Date% %Time%
		set Lost=0
	)
	"%~dp0sleep.exe" -m 1000
)
goto :loop

Open in new window

0
 

Author Comment

by:100questions
Comment Utility
@obda - thanks however it seems that the system requirements for the download are Windows Server 2003 and XP, none of which is available.
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
As I said, you have two options:
* You can download it (download is possible just fine on Windows 7), then extract the first the msi from the exe, then sleep.exe from the msi using 7-Zip. You could even install it anyway on a test machine (I have it installed on Windows 7), it mainly unpacks a bunch of tools into C:\Program Files (x86)\Windows Resource Kits\Tools) and then copy sleep.exe into the script's folder.
Or you can replace line 28 in the script (where currently sleep.exe is called) with "ping.exe -n 2 localhost >NUL" (minus the quotes, of course).
0
 

Author Comment

by:100questions
Comment Utility
@kimputer - when I try using hrping and clicking on it nothing happens, no graphical interface.. it creates a log file but I have no idea if it's running..
0
 

Author Comment

by:100questions
Comment Utility
@oBdA - Thanks.  I am concerned with licencing.  Windows Server 2003 or XP are not being used.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Then use this version:
@echo off
setlocal
mode con cols=40 lines=25
if "%~1"=="" (
	set /p IP=Name oder IP: 
) else (
	set IP=%~1
)
title Ping %IP%
set LogFile=%~dpn0-%IP%.log
set Lost=X
:loop
ping.exe -n 1 %IP% | find /i "TTL" >NUL
if errorlevel 1 (
	if not %Lost%==1 (
		color 4F
		echo - Down: %Date% %Time: =0%
		>>"%LogFile%" echo - %Date% %Time%
		set Lost=1
	) 
) else (
	if not %Lost%==0 (
		color 2F
		echo + Up: %Date% %Time: =0%
		>>"%LogFile%" echo + %Date% %Time%
		set Lost=0
	)
	ping.exe -n 2 localhost >nul
)
goto :loop

Open in new window

0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
hrping behaves exactly like ping. You don't double click on it, you open a command prompt, then type the name and options, then press enter.
grping is the graphic view, and you invoke it from command line with the -g option, if I'm not mistaken.

You'll find a hrping.txt file in the archive you downloaded, which is basically the manual for the utility.
0
 

Author Comment

by:100questions
Comment Utility
@oBDA- Thanks.  Is this batch or vbs?
0
 

Author Comment

by:100questions
Comment Utility
@oBDA - thanks it works as a batch file.  How will I know if the connection is cut for some reason, will it log it.  When I started it it says Up..  does that mean it's working fine, and there are no connectivity issues?
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
The script will create a log file as <script name><target name>.log in its folder, so if the script is called Whatever.cmd and you ping google.com, the log file will be "Whatever-google.com.log".
"Up" and the green background (in the log file, it's a simple "+") means that it currently pings successfully; "Down" and the red background (a "-" in the log file) means the ping is currently lost.
0
 

Author Comment

by:100questions
Comment Utility
@oBdA - Thanks.   Ok, and does it keep a log when there are disconnects in the internet then, the Down times?
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Yes, as I said; it will log (only) the times when a connection changes status, that is, a ping is lost after a successful ping, or a ping is successful after a failed ping. So a log like this
+  12/1/2014 01:02:03
-  12/1/2014 02:03:04
+  12/1/2014 03:04:05

Open in new window

means that the connection was established at 01:02:03, was successful until 02:03:04 when it dropped, and it stayed dropped until 03:04:05 when it was established again.
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
I've got a few scripts of mine for monitoring here if you want to play, though I like oBdA's logging of a change in status only.

http://scripts.dragon-it.co.uk/links/batch-ping-list-of-hosts-3

If you search for "ping" there are 4-5 similar but different including emailing faults - what I tend to do is keep a log of faults then perioidcally it checks for that log and emails it:

http://scripts.dragon-it.co.uk/links/batch-monitor-ping-email

Steve
0
 

Author Closing Comment

by:100questions
Comment Utility
Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now