Evil_TTL> show | s

Ping To File With Timestamp

Category:Tools -> Monitoring

In this article I would like to introduce a ping script that sends ICMP echo requests, receives ICMP echo replies from hosts, and saves the results into a text file with a timestamp. The ping script is universal and can be copy-pasted into a batch file (*.bat). It works, at least intended to work, on any Windows operating system without need for Power Shell or other additional software. The script creates a *.txt file in the same directory and saves the data into it.

The simplest variation of the script is the following:


Ping-To-File-With-Timestamp-10.PNG
* sorry for images, I couldn’t insert a code of such kind into the article because of web-site engine limitations.

It sends 10 echo requests to host 172.16.3.105 with 1024 bytes and places timestamps in increments of 10 seconds. The advantages of this script are in the simplicity and lack of requirements for additional utilities to be installed. It saves all data into the text file without exceptions. The disadvantage is in the increased timestamp increments equaled to 10 seconds.

See the output from the file:

21.05.2014 17:34:47,32 Pinging 172.16.3.105 with 1024 bytes of data
21.05.2014 17:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:47,32 Ping statistics for 172.16.3.105
21.05.2014 17:34:47,32 -     PacketsSent 10Received 10Lost 
21.05.2014 17
:34:47,32 -     (0loss
21.05.2014 17:34:47,32 Approximate round trip times in milli-seconds
21.05.2014 17:34:47,32 -     Minimum 1msMaximum 1 msAverage 1 ms 
21.05.2014 17
:34:56,43 Pinging 172.16.3.105 with 1024 bytes of data
21.05.2014 17:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:34:56,43 Ping statistics for 172.16.3.105
21.05.2014 17:34:56,43 -     PacketsSent 10Received 10Lost 
21.05.2014 17
:34:56,43 -     (0loss
21.05.2014 17:34:56,43 Approximate round trip times in milli-seconds
21.05.2014 17:34:56,43 -     Minimum 1msMaximum 1 msAverage 1 ms 
21.05.2014 17
:35:05,58 Pinging 172.16.3.105 with 1024 bytes of data
21.05.2014 17:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Reply from 172.16.3.105bytes=1024 time=1ms TTL=255 
21.05.2014 17
:35:05,58 Ping statistics for 172.16.3.105
21.05.2014 17:35:05,58 -     PacketsSent 10Received 10Lost 
21.05.2014 17
:35:05,58 -     (0loss
21.05.2014 17:35:05,58 Approximate round trip times in milli-seconds
21.05.2014 17:35:05,58 -     Minimum 1msMaximum 1 msAverage 1 ms 

To improve the ping script and make sure the timestamp is placed in increments of ~1 second we need to modify the script in the following way:

Ping-To-File-With-Timestamp-20.PNG

Two additional commands “findstr” and “sleep” were added to the script. The number of echo requests was reduced to 1. The modified script will write to the text file only successful replies and timed out requests with a proper timestamp.

Example:

26.05.2014 12:35:29,92 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:31,14 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:32,29 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:33,43 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:34,59 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:35,74 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:36,97 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:38,13 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:39,28 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:40,42 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:41,57 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:42,85 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:43,99 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:45,14 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:46,28 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 
26.05.2014 12
:35:47,45 Reply from 192.168.10.1bytes=1024 time=1ms TTL=255 

There is a precaution – findstr and sleep utilities must be preinstalled before the script execution. If findstr is typically preinstalled in the operating system then sleep utility is not and has to be downloaded separately and placed in the same directory with the batch file. You can download sleep utility from here: File:sleep.zip

There is also a handy utility called Bat_To_Exe_Converter that helps you convert any *.bat script into a single *.exe file with attached binary files. It will help you hide the contents of the batch file and store any binaries like sleep.exe, for example, in a single executable container.

To download Bat_To_Exe_Converter  address the following link: File:Bat_To_Exe_Converter.zip

DISCLAIMER: All software belongs to 3rd parties. Although I checked it for viruses, download at your own risk!

Instructions on how to use the software:

Bat To Exe Converter 



1. What does this program 
do? 
It will convert batch-scripts to executables.

2. Hot to install/uninstall it
This tool does not require an installation.

3. How to use it?
Execute the file named Bat_To_Exe_Converter.exe and select a batch-file.
You can add additional binaries to your resulted program by using the Include function.
You can also set an icon and versioninformationchoose an icon and fill out the "additional information" fields.

4. How to use it from the command line?
To compile your batch-files from command line run it with the parametersYou must run it with 4 or more parameters.
The first parameter must be the name of your batch filethe second one must be the output file name of your program,
the third can be the name of your icon filethe fourth one is the visibility flag.
All following parameters are optional and treated as additional binaries.

Examples:

1
Bat_To_Exe_Converter [ mybatchfile.bat ] [ myprogram.exe ] [ myicon.ico ] [ 1 ] mypicture1.jpg > < mysong.mp3 >

This example converts "mybatchfile.bat" to "myprogram.exe" and adds an icon and two additional binaries in itThe application is visible.

2
Bat_To_Exe_Converter [ mybatchfile.bat ] [ myprogram.exe ] [ "" ] [ 0 ] 

This example converts 
"mybatchfile.bat" to "myprogram.exe"The application is invisible
By privilege15