> For the complete documentation index, see [llms.txt](https://valineliu.gitbook.io/deuterium-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valineliu.gitbook.io/deuterium-wiki/reading/cs-jing-dian-shu-ji/tcpv1/ch07-ping-program.md).

# ch07: Ping Program

ICMP

## MindMap

![Ping Program](https://tva1.sinaimg.cn/large/007S8ZIlly1gg7tv57c14j30vs0u0doo.jpg)

## Intro

* 用来测试一个主机是否可达；
* 使用ICMP，发送一个echo请求，期待一个echo应答；
* 如果ping不通，那么也不能Telnet和FTP；
* 可以用来获得两个主机间的rrt（round-trip time）。

## 格式

echo请求和echo应答的格式如下：

![image-20200628111652577](https://tva1.sinaimg.cn/large/007S8ZIlly1gg7u2321ijj310o0ewta9.jpg)

* 类型0是echo应答，8是echo请求；
* Unix实现中使用ping的进程ID作为标识符（identifier）；
* 序号（sequence number）从0开始，返回一个应答就增一。

## IP记录路由选项

可以通过ping来查看IP记录路由（record route， RR），使用`-R`选项。

* 路径上的每一个路由器都在echo请求中加上自己的IP；
* 路上的IP列表在echo应答中复制过来；
* 返回路径上的路由器也加上自己的IP。

唯一的问题就是空间不够。

格式：

![image-20200628113258025](https://tva1.sinaimg.cn/large/007S8ZIlly1gg7uiuidusj311y09ymy7.jpg)

最多只能记录9个。

路由器记录的是出口的IP地址。

这个也没啥大用，可以使用**traceroute**。

## IP时间戳选项

和IP记录路由选项类似，格式如下：

![image-20200628113743674](https://tva1.sinaimg.cn/large/007S8ZIlly1gg7uns3t32j313g08mdgt.jpg)

没啥用这个选项。
