Ping and Traceroute inside Windows and Linux
Created: 2018-09-05 01:39:13 | Last modified: 2024-02-20 20:54:52
Access: Read | Views: 315 | Rating: N/A | Tags: windows cmd ping linux
Here is how to ping or traceroute using the Windows command prompt or the Linux CLI. There are options for using a timestamp and fragmentaion options
Time Stamp Ping
Windows
Create a batch file e.g. ping.bat with the following text. Replace with an IP address. 10.30.0.12 with the IP address you wish to ping.
Example
# Display in CLI
@echo off
ping -t 10.30.0.12 | cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!time! !data!)&ping -n 2 10.30.0.12 > nul"
# Write to file
@echo off
ping -t 10.30.0.12 | cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!time! !data!)&ping -n 2 10.30.0.12 > nul" > filename.txt
Linux
This can be done directly on the CLI. Replace with an IP address. 10.30.0.12 with the IP address you wish to ping.
# Display in CLI
ping 10.30.0.12 | while read pong; do echo "$(date): $pong"; done
# Write to file
ping 10.30.0.12 | while read pong; do echo "$(date): $pong"; done > filename
MTU and Fragmentation
Sometimes you might not be able to access some sites on the web, of have connection issues to certain services (Especially over a VPN). Sometimes it is worth trying to work out when fragmentation happens.
Windows
# Ping with a 1472 MTU with the do not fragment (-f) flag set
ping –l 1472 –f 10.30.0.12
Linux
# Ping with a size of 1472 MTU with the do not fragment (-M do) flag set
ping -s 1472 -M do 10.30.0.12
Timeout
You can ping with a timeout, by default Windows does this, but in Linux you need to add the -O flag. This works on most distros
ping -O 10.30.0.12
Time Stamp Traceroute
Linux
To do a timestamp traceroute in Linux, use the following command. Replace 10.30.0.12 with the destination you wish to trace route to. The command will sleep for 1 second between each of the traceroutes.
while true; do traceroute 10.30.0.12 | while read pong; do echo "$(date): $pong"; done >> traceroute_file.txt; sleep 1; done