Ping在线检测工具

域名或 IP地址

Ping次数

Ping时间间隔


关于Ping在线检测工具:

这个在线ping工具从Linux服务器返回ping结果. 您可以选择ping域名的次数,以及两次ping查询之间的时间间隔.

comic ping

Ping域名需不需要加www.前缀?

对于一部分网站,您必须加 www 前缀,例如 www.microsoft.comwww.quora.com. 如果ping检测失败, 请实施在域名之前加 www. 前缀. 这是因为一些域名所有者设置DNS没有使用默认的设置.

为什么需要使用Ping检测?

你有没有在Skype对话中经历过长时间延迟? 您是否对在线游戏时感受延迟? 你应该检测从你家到网站的延迟时间.

Ping检测计算从您家到任何具有公共IP地址或域名的Web服务器的往返时间(从您单击从Web服务器返回内容的链接). 它还会告诉您有多少数据包已传输,已接收的数据包数以及已丢失的数据包数.

对于在线游戏,游戏服务器的ping延迟应保持在100ms之下,如果ping延迟超过200ms则体验无法忍受. 对于常规的Web浏览活动,ping 延迟对上网体验影响较小. ping延迟和Internet速度是2个不同的概念,高延迟并不意味着你只能忍受 480p 分辨率的Netflix,虽然ping延迟和Internet速度是经常体现为正相关.

有几种方法可以降低ping延迟,大互联网流量会对ping延迟产生负面影响,因此夜间的互联网速度更快,包裹丢失率低于白天.

更多关于ping检测的链接:

维基百科 (ping): https://en.wikipedia.org/wiki/Ping_(networking_utility)

RFC 792 (ping): https://tools.ietf.org/html/rfc792

Linux系统中的ping检测 (Ubuntu): https://linux.die.net/man/8/ping

Windows系统中的ping检测: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ping

Linux系统中的ping检测命令:

NAME
       ping - send ICMP ECHO_REQUEST to network hosts

SYNOPSIS
       ping  [-aAbBdDfhLnOqrRUvV46] [-c count] [-F flowlabel] [-i interval] [-I interface] [-l preload]
       [-m mark] [-M pmtudisc_option] [-N nodeinfo_option] [-w deadline] [-W timeout] [-p pattern]
       [-Q tos] [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp option] [hop ...] destination

root@instance-1:/var/log/apache2# ping -c 4 -i 1 facebook.com
PING facebook.com (157.240.22.35) 56(84) bytes of data.
64 bytes from edge-star-mini-shv-01-sjc3.facebook.com (157.240.22.35): icmp_seq=1 ttl=52 time=19.1 ms
64 bytes from edge-star-mini-shv-01-sjc3.facebook.com (157.240.22.35): icmp_seq=2 ttl=52 time=18.6 ms
64 bytes from edge-star-mini-shv-01-sjc3.facebook.com (157.240.22.35): icmp_seq=3 ttl=52 time=18.9 ms
64 bytes from edge-star-mini-shv-01-sjc3.facebook.com (157.240.22.35): icmp_seq=4 ttl=52 time=18.7 ms

--- facebook.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 18.697/18.857/19.102/0.189 ms
    

用Python进行ping IP地址或域名 (用 package socket):

  1. import socket
  2. import time
  3.  
  4.  
  5. def ping(ip_or_domain, count):
  6. for i in range(1, count):
  7. try:
  8. start_time = time.time()
  9. socket.gethostbyname(ip_or_domain)
  10. end_time = time.time()
  11. total_time = round((end_time - start_time) * 1000, 2)
  12. print('{0} is reachable: icmp_seq={1} time={2}ms'.format(ip_or_domain, i, total_time))
  13. except socket.herror:
  14. print('{0} is NOT reachable'.format(ip_or_domain))
  15.  
  16.  
  17. if __name__ == "__main__":
  18. # ping ip address
  19. ping("93.184.216.34", 4)
  20. # ping domain
  21. ping("coding.tools", 2)
  22.  
  23. -------------------
  24. 93.184.216.34 is reachable: icmp_seq=1 time=19ms
  25. 93.184.216.34 is reachable: icmp_seq=2 time=31ms
  26. 93.184.216.34 is reachable: icmp_seq=3 time=15ms
  27. 93.184.216.34 is reachable: icmp_seq=4 time=13ms
  28. coding.tools is reachable: icmp_seq=1 time=14ms
  29. coding.tools is reachable: icmp_seq=2 time=7ms

用Java进行ping IP地址或域名 (用 package java.net.InetAddress):

  1. import java.io.IOException;
  2. import java.net.InetAddress;
  3.  
  4. public class Ping {
  5. public static void ping(String ip_or_domain, int count) throws IOException {
  6. InetAddress remote_host = InetAddress.getByName(ip_or_domain);
  7. // send ping request "count" times in total
  8. for (int i = 1; i <= count; i++) {
  9. // Sending ping request
  10. long start_time = System.currentTimeMillis();
  11. boolean is_reachable = remote_host.isReachable(5000);
  12. long end_time = System.currentTimeMillis();
  13. long total_time = end_time - start_time;
  14. if (is_reachable)
  15. System.out.println(ip_or_domain + " is reachable: icmp_seq=" + i + " time=" + total_time + "ms");
  16. else
  17. System.out.println(ip_or_domain + "is NOT reachable");
  18. }
  19. }
  20.  
  21. public static void main(String[] args) throws IOException {
  22. // ping ip address
  23. ping("93.184.216.34", 4);
  24. // ping domain
  25. ping("coding.tools", 2);
  26. }
  27. }
  28.  
  29. -------------------
  30. 93.184.216.34 is reachable: icmp_seq=1 time=19ms
  31. 93.184.216.34 is reachable: icmp_seq=2 time=19ms
  32. 93.184.216.34 is reachable: icmp_seq=3 time=15ms
  33. 93.184.216.34 is reachable: icmp_seq=4 time=14ms
  34. coding.tools is reachable: icmp_seq=1 time=8ms
  35. coding.tools is reachable: icmp_seq=2 time=3ms