This example utilizes ping in conjunction with febooti Command line email tool to update a network administrator if a particular network connection has become inactive. The ping command will be called from within a batch file and the result analyzed. If a successful reply has been received from the remote device then no action is taken. However if a ping request fails, then an email from a DOS batch file is sent using Command line email tool to the network administrator so that appropriate action can be taken if required. The remote host or device can be any network device with an IP address or a standard URL name.
Solution:
1. A batch file should be created as per the example below.
2. A new task should be added using the Windows task scheduler that runs the above batch file every 5 minutes. In Windows XP the task scheduler can be accessed from Start | Programs | Accessories | System Tools and by clicking on the Scheduled Tasks menu item. A new task can be added by selecting New | Scheduled Task from the File menu. Once the task has been created, the batch file (PingTest.bat) and actual schedule can be defined by right-clicking on the task and selecting Properties.
@echo off
rem Set IP addresses for network computers... SET DEVICE1_IPADDRESS=192.168.0.1 SET DEVICE2_IPADDRESS=192.168.0.2 rem add more DEVICE_IPADDRESS here if needed...
rem Perform all network computer ping... rem If error occurs, send email to email specified...
rem Perform 1st computer ping... PING -n 1 -w 5000 %DEVICE1_IPADDRESS% | find "TTL=" || febootimail -SERVER outgoing.mail.server.com -FROM noreply@pingadmin.com -TO admin@company-network.com -SUBJECT ALERT: No reply from device -MSG Warning: There was no reply when performing a ping request on device with IP address %DEVICE1_IPADDRESS%
rem perform 2nd computer ping... PING -n 1 -w 5000 %DEVICE2_IPADDRESS% | find "TTL=" || febootimail -SERVER outgoing.mail.server.com -FROM noreply@pingadmin.com -TO admin@company-network.com -SUBJECT ALERT: No reply from device -MSG Warning: There was no reply when performing a ping request on device with IP address %DEVICE2_IPADDRESS%
rem Ping more network computers if needed...
1: The first two commands in the batch file define two separate variables. Each of these variables stores an IP address for each of the devices. More devices can be added if necessary in this manner.
2: The ping commands are exactly the same - they only differ in the variable they use to define an IP address for the network device. Once a variable has been defined it is referenced with percentage % symbols on both sides.
3: The above format for the ping command attempts to ping the specified network device once and with a timeout of 5000 milliseconds (5 seconds).
4: The | find "TTL=" command attempts to find the text TTL= in the output generated by the ping command. Using this method ensures a definite reply has been sent back from the particular device.
5: If there is a reply no further action is taken, however if there is no response to the ping command from the pinged device then an email is sent to the network administrator using febooti Command line email tool. The arguments used for this email tool are self-explanatory.