Skip to the content.

ping: ICMP Ping Code Examples for Raspberry Pi, Raspberry Pi Pico, and ESP32

ICMP Ping の送信や受信を行うサンプル・プログラムです。
This repository contains ICMP Ping examples for leaning Ping protocol.


Select a language to translate this page:

Usage for Raspberry Pi

The “.py” example files on the root directory are for Raspberry Pi OS and the other Linux distributions. I tested them on Ubuntu 22 and Debian 11.
These files are needed the super user privileges. So, please add a “sudo” command to the beginning of these files to run.

pi@raspberry:~/ping $ sudo ./  
ICMP Ping Sender Receiver  
Usage: sudo ./ [ip_address] [data...]  
send Ping to  
ICMP TX(08) : 08 00 93 c0 e5 b9 7e 85  
ICMP RX(08) : 00 00 9b c0 e5 b9 7e 85  
IP Version  = v4  
IP Header   = 20  
IP Length   = 28  
Protocol    = 0x01  
Source      =  
Destination =  
ICMP Length = 8  
ICMP Type   = 00  
ICMP Code   = 00  
Checksum    = Passed  
Identifier  = e5b9  
Sequence N  = 7e85  

Usage for Raspberry Pi Pico W, ESP32 (MicroPython)

In the “pico” and “esp32” directories, there are also some files coded in MicroPython for Raspberry Pi Pico W, ESP32.
“” and “” send ICMP Pings to Google DNS ( If you don’t like to send out from your LAN to Internet, please modify the IP address in the line of “adr = ‘’” to your device on the LAN.

adr = ''         # Google DNS
adr = ''     # e.g., Gateway on the LAN

“” and “” are for local uses. is for the server side, and the other is for the client. Blog Site

Security of Super User Privileges

The command added ‘sudo’ works the highest privileges on the system. It means the code behave without any limitations.
If there are security weaknesses in a code, in software libraries, or in the operating system, and the device meets maliciously attacks, you may have a security accident.
For improving way of the security for the kind of this code, is to reduce the external inputs and outputs. And checking all of the input data and discarding unwanted messages is one of the most important countermeasures for the security issue.

GitHub Pages (This Document)