聊聊Ping命令的返回值Pong

聊聊Ping命令的返回值Pong,第1张

Pong 是什么?见文末~

在写程序代码、运维时经常会使用ping测试连通性,成功时也会看到一个返回值Pong
为什么不返回success呢,如果不了解ICMP协议就不能窥探原因。
下面看看返回Pong的示例:

一、使用java中的Jedis类连接Redis测试时:

Jedis 是 Redis 官方首选的 Java 客户端开发包。
1.测试连通性
public class Demo01 {
  public static void main(String[] args) {
    //连接本地的 Redis 服务
    Jedis jedis = new Jedis("127.0.0.1",6379);
    //查看服务是否运行,打出pong表示OK
    System.out.println(jedis.ping());
  }

java中使用jedis测试连通性返回值pong

二、使用Ansible运维时:

检查指定节点机器是否还能连通,用法很简单,不涉及参数,主机如果在线,则回复pong

[root@localhost ~]# ansible erp -m ping
192.168.10.6 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.10.7 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

ping = protocol ICMP, type 8(request), code 0
pong = protocol ICMP, type 0(reply), code 0

Ping is a computer network application used to test whether a particular host is reachable across an IP
network. It is also used to self-test the network interface card of the computer or as a latency test. It works
by sending ICMP “echo reply” packets to the target host and listening for ICMP “echo reply” replies. The
“echo reply” is sometimes called a pong. Ping measures the round-trip time, records packet loss, and
prints a statistical summary of the echo reply packets received (the minimum, maximum, and the mean of
the round-trip times and in some versions the standard deviation of the mean).

参考连接
http://gaia.cs.umass.edu/kurose_ross/programming/Python_code/ICMPping.pdf

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/720835.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存