Follow

Ping Testing

The ping utility is very useful in verifying connectivity across the network, but it can be quite verbose when running a longer test. Unfortunately, many network connectivity issues are intermittent. An effective ping test for gathering information would perform the following:

  1. Only collect failed ping results (no response, host unavailable, etc...).
  2. Run infinitely without user interaction.
  3. Note a date and time stamp for the failure.
  4. Log to a file for later analysis and cross-referencing with other logs.

The ping utility only has options to meet #2 and #4, so at DoxTek we have written a batch script that will flesh out the behavior and meet all requirements:

@echo off
setlocal enableExtensions

REM Runs an infinite ping while writing failures with timestamp to a log file
REM Author: James Daughtry (DoxTek)

REM Check for a help option
if /i %1 equ /? (
	echo Usage: pingtest [/i] target_name output_file
	echo /i Echo results to the command prompt 
	exit /B 0
)

set @interactive=0

REM Check for an optional interactive option to echo to the command prompt
if /i %1 equ /i (
	echo Interactive mode enabled, errors will be written to this window
	set @interactive=1
	shift /1
)

:loop
	ping -n 1 %1 > nul
	
	if %errorlevel% equ 1 (
		echo %date% %time% no reply from %1 >> %2

		REM Also echo to the command prompt in interactive mode
		if %@interactive% equ 1 (
			echo %date% %time% no reply from %1
		)
	)

	choice /N /T 1 /D Y >nul
	goto loop

This code can be saved as a text file with a .bat or .cmd extension and run from the Windows command prompt like so:

C:>pingtest.cmd /i localhost pinglog.txt

The /i option will also duplicate messages to the command prompt, and failure messages will appear in the log in the following format:

Wed 09/09/2015 13:53:45.90 no reply from locahost

These messages can then be used to cross-reference with error messages from other applications or even the Windows event log to identify whether those errors are related to network connectivity where access to a network resource was unavailable at the time.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk