Ping在线检测工具
关于Ping在线检测工具:
这个在线ping工具从Linux服务器返回ping结果. 您可以选择ping域名的次数,以及两次ping查询之间的时间间隔.
Ping域名需不需要加www.前缀?
对于一部分网站,您必须加 www 前缀,例如 www.microsoft.com 和 www.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):
import socket
import time
def ping(ip_or_domain, count):
for i in range(1, count):
try:
start_time = time.time()
socket.gethostbyname(ip_or_domain)
end_time = time.time()
total_time = round((end_time - start_time) * 1000, 2)
print('{0} is reachable: icmp_seq={1} time={2}ms'.format(ip_or_domain, i, total_time))
except socket.herror:
print('{0} is NOT reachable'.format(ip_or_domain))
if __name__ == "__main__":
# ping ip address
ping("93.184.216.34", 4)
# ping domain
ping("coding.tools", 2)
-------------------
93.184.216.34 is reachable: icmp_seq=1 time=19ms
93.184.216.34 is reachable: icmp_seq=2 time=31ms
93.184.216.34 is reachable: icmp_seq=3 time=15ms
93.184.216.34 is reachable: icmp_seq=4 time=13ms
coding.tools is reachable: icmp_seq=1 time=14ms
coding.tools is reachable: icmp_seq=2 time=7ms
用Java进行ping IP地址或域名 (用 package java.net.InetAddress):
import java.io.IOException;
import java.net.InetAddress;
public class Ping {
public static void ping(String ip_or_domain, int count) throws IOException {
InetAddress remote_host = InetAddress.getByName(ip_or_domain);
// send ping request "count" times in total
for (int i = 1; i <= count; i++) {
// Sending ping request
long start_time = System.currentTimeMillis();
boolean is_reachable = remote_host.isReachable(5000);
long end_time = System.currentTimeMillis();
long total_time = end_time - start_time;
if (is_reachable)
System.out.println(ip_or_domain + " is reachable: icmp_seq=" + i + " time=" + total_time + "ms");
else
System.out.println(ip_or_domain + "is NOT reachable");
}
}
public static void main(String[] args) throws IOException {
// ping ip address
ping("93.184.216.34", 4);
// ping domain
ping("coding.tools", 2);
}
}
-------------------
93.184.216.34 is reachable: icmp_seq=1 time=19ms
93.184.216.34 is reachable: icmp_seq=2 time=19ms
93.184.216.34 is reachable: icmp_seq=3 time=15ms
93.184.216.34 is reachable: icmp_seq=4 time=14ms
coding.tools is reachable: icmp_seq=1 time=8ms
coding.tools is reachable: icmp_seq=2 time=3ms