POng is Not pinG.
Tags: go, ping, pong, jokes
Published: 2023-04-24 14:06:28

I created the pong command in Go language.

See below for a run-time image.

![demo](https://github.com/yoshi389111/pong-is-not-ping/raw/main/docs/pong.gif)

This command was inspired by the existing awesome pong command.

That awesome pong command was created by [kurehajime](https://github.com/kurehajime).

{% embed https://github.com/kurehajime/pong-command %}

In this pong command, the target hostname you enter will take the place of the ball.

Sounds like a great idea, doesn't it?

The key types for `pong` and `ping` are similar (`O` and `I` next to each other in QWERTY).
Therefore, I feel that it is similar to the key type correction effect of the `sl` command for the `ls` command.

* Ubuntu manuals: [sl(6)](https://manpages.ubuntu.com/manpages/bionic/man6/sl.6.html)

If you thought the above article and command ideas were great, I encourage you to star the [repository](https://github.com/kurehajime/pong-command) before reading the rest of the text.

When I saw this command, I thought, "Great idea."
However, at the same time, I thought, "Is there another possibility?"

So let's start by looking at the pong game and the ping command.

## What is pong game?

It is a game like so-called table tennis (ping pong).
Various pong games have been created since recorded history.

{% embed https://en.wikipedia.org/wiki/Pong %}

It is common for two players to play against each other, or for users against computers.
There are paddles (or racquets) on the left and right (or top and bottom) of the screen, and players operate the paddles to hit the ball.

I think it is no exaggeration to say that it is probably the beginning of e-sports.

## What is the ping command?

The ping command is a command that checks whether there is a response from a device with a specific IP address on the IP network.

The ping command is usually executed by specifying the target host (IP address or hostname).

The executed ping command will send an ICMP protocol echo request packet towards the target.
When the target host receives an ICMP echo request packet, it returns an echo reply packet to the source (some hosts do not respond due to settings, etc.).

If the target host is not on the same network, the gateway between networks will relay the echo request/reply packets. At that time, the TTL (Time To Live) value in the packet is decremented by 1, and if the result of the decrement is 0, the packet is not relayed and discarded.

The ping command records network reachability, response time, etc. by receiving or not returning an ICMP echo reply from the target host.

Depending on the execution environment and option specification, it sends and receives ICMP echo packets for a specified number of times or until the user stops (such as CTRL+C), and finally reports the result.

{% embed https://en.wikipedia.org/wiki/Ping_(networking_utility) %}

## I created the pong command.

After examining the similarities and differences between the pong game and the ping command, I created the pong command.

![demo](https://github.com/yoshi389111/pong-is-not-ping/raw/main/docs/pong.gif)

When you run the pong command with a target host, the local host (on the far left of the screen) will send an ICMP ECHO packet.

On the target host (the paddle you control on the right), take the incoming ICMP ECHO packets and send them back to the host that sent them (the localhost on the far left).

However, the Gateway (the paddle on the left side of the screen, operated by the computer) in between, for whatever reason, always sends it back to the target host when it receives an ICMP ECHO packet.
So you need to send an ICMP ECHO packet back to the localhost while avoiding the Gateway.
When the Gateway sends back, the TTL is decremented, so send it back before the TTL runs out (by default the TTL starts from 64).

Also, if you send back many times, the network speed will gradually increase. be careful.

By default, the local host will send ICMP ECHO packets 4 times.
After the last packet has been received (or lost), or if the user has stopped, display packet response state statistics up to that point.

The starting method of this pong command is as follows.

```
pong [options] <destination>
```

The following can be specified as options.

```
Application Options:
  -h, --help                 print help and exit
  -v, --version              print version and exit
  -c, --count=<count>        stop after <count> replies (default: 4)
  -t, --ttl=<ttl>            define time to live (default: 64)
  -p, --padding=<pattern>    contents of padding byte

Arguments:
  <destination>:             dns name or ip address
```

The source code is on GitHub.

{% embed https://github.com/yoshi389111/pong-is-not-ping %}

The Japanese version of this article is below.

* Qiita: [Go言語でpingコマンドっぽい、でもpingコマンドじゃないpongコマンドを作ってみた](https://qiita.com/yoshi389111/items/a289f1c470616c5f10c4)