Nping is a utility designed to ease the process of crafting network packets. It is very useful to debug and troubleshoot network communications and perform traffic analysis. For example, if we want to debug certain network connections, we can easily use Nping to determine what’s happening on the wire. The following shows a basic Nping command:
$ sudo nping -c2 thegeekdiary.com -p80 --tcp
Let’s say that we want to respond to an ICMP echo request packet with an echo reply using Nping. Consider that the first ICMP echo request packet has a source IP of 192.168.0.10 with an ICMP ID of 520, and the data string was the word ping. With that information, we can craft the reply with the following command:
# nping --icmp -c 1 --icmp-type 0 --icmp-code 0 --source-ip 192.168.0.5 --dest-ip 192.168.0.10 --icmp-id 520 --icmp-seq 0--data-string 'ping'
In the output, you should see the sent ICMP echo reply packet with the values taken from the ICMP echo request packets:
SENT (0.0060s) ICMP [192.168.0.5 > 192.168.0.10 Echo reply (type=0/code=0) id=520 seq=0] IP [ttl=64 id=10898 iplen=32 ] Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A Raw packets sent: 1 (32B) | Rcvd: 0 (0B) | Lost: 1 (100.00%) Nping done: 1 IP address pinged in 1.01 seconds
If you encounter the below error while running the nping command:
nping: command not found
you may try installing the nmap package as shown below as per your choice of distribution:
Distribution | Command |
---|---|
OS X | brew install nmap |
Debian | apt-get install nmap |
Ubuntu | apt-get install nmap |
Alpine | apk add nmap |
Arch Linux | pacman -S nmap |
Kali Linux | apt-get install nmap |
Fedora | dnf install nmap-2 |
Raspbian | apt-get install nmap |