除了回显请求外,还可以利用icmp来实现时间请求。在icmp的数据包中可以包含发送时间,目的主机收到后再附上自身当时时间才发回。这样可以做一个时间校验,并可以判断源与目的之间的通讯速度。由于具体的内容部分比较烦,类型太多,一下子记不住各个类型的意思。
一般用ping的时候只是用了它的最简单的功能:检查主机能不能连到。其实使用它所提供的其他选项,可以实现许多细节上的控制,例如数据包长度,TTL,路由记录,宽/严路由经过路由等。
tracetroute,也就是 trace route,跟踪路由。这个程序最早是Van Jacobson实现的。源码在网上可以找到,不过我还没有去找。主要的原理是IP路由过程中对数据包TTL(Time to Live,存活时间)的处理。当路由器收到一个IP包时,会修改IP包的TTL(及由此造成的头部检验和checksum变化)。每收到一个包,检查这个的TTL是否是0或1。如果是,表明这个包还没有到达目的地,而且剩余时间不多了,肯定是到不了目的地了。这样路由器就简单地丢弃这个包,并给源主机发送 ICMP通知,说这个包已经超时了。ICMP的通知信息里包含当前路由器发送时所用的IP。
ping命令--详细帮助
校验与远程计算机或本地计算机的连接。只有在安装 TCP/IP 协议之后才能使用该命令。
ping [-t] [-a] [-n count] [-l length] [-f] [-i ttl] [-v tos] [-r count] [-s count] [[-j computer-list] | [-k computer-list]] [-w timeout] destination-list
参数
-t
校验与指定计算机的连接,直到用户中断。
-a
将地址解析为计算机名。
-n count
发送由 count 指定数量的 ECHO 报文,默认值为 4。
-l length
发送包含由 length 指定数据长度的 ECHO 报文。默认值为 64 字节,最大值为 8192 字节。
-f
在包中发送“不分段”标志。该包将不被路由上的网关分段。
-i ttl
将“生存时间”字段设置为 ttl 指定的数值。
-v tos
将“服务类型”字段设置为 tos 指定的数值。
-r count
在“记录路由”字段中记录发出报文和返回报文的路由。指定的 Count 值最小可以是 1,最大可以是 9 。
-s count
指定由 count 指定的转发次数的时间邮票。
-j computer-list
经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(松散的源路由)。允许的最大 IP 地址数目是 9 。
-k computer-list
经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(严格源路由)。允许的最大 IP 地址数目是 9 。
-w timeout
以毫秒为单位指定超时间隔。
destination-list
指定要校验连接的远程计算机。
关于 Ping 的详细信息
Ping--注意
Ping 命令通过向计算机发送 ICMP 回应报文并且监听回应报文的返回,以校验与远程计算机或本地计算机的连接。对于每个发送报文, Ping 最多等待 1 秒,并打印发送和接收把报文的数量。比较每个接收报文和发送报文,以校验其有效性。默认情况下,发送四个回应报文,每个报文包含 64 字节的数据(周期性的大写字母序列)。
可以使用 Ping 实用程序测试计算机名和 IP 地址。如果能够成功校验 IP 地址却不能成功校验计算机名,则说明名称解析存在问题。这种情况下,要保证在本地 HOSTS 文件中或 DNS
数据库中存在要查询的计算机名。
下面显示 Ping 输出的示例:(Windows用户可用:开始->运行,输入"command" 调出command窗口使用此命令)
C:\>ping -a 192.168.1.21
Pinging iceblood.yofor com [192.168.1.21] with 32 bytes of data:
Reply from 192.168.1.21: bytes=32 time<10ms TTL=254
Reply from 192.168.1.21: bytes=32 time<10ms TTL=254
Reply from 192.168.1.21: bytes=32 time<10ms TTL=254
Reply from 192.168.1.21: bytes=32 time<10ms TTL=254
Ping statistics for 192.168.1.21:
Packets: Sent = 4,Received = 4,Lost = 0 (0% loss),Approximate round trip times in milli-seconds:
Minimum = 0ms,Maximum = 0ms,Average = 0ms
从上面就可以知道IP为192.168.1.21的计算机NetBios名为iceblood.yofor com。
C:\>ping -n 1 -r 9 202.96.105.101 (发送一个数据包,最多记录9个路由)
Pinging 202.96.105.101 with 32 bytes of data:
Reply from 202.96.105.101: bytes=32 time=10ms TTL=249
Route: 202.107.208.187 ->
202.107.210.214 ->
61.153.112.70 ->
61.153.112.89 ->
202.96.105.149 ->
202.96.105.97 ->
202.96.105.101 ->
202.96.105.150 ->
61.153.112.90
Ping statistics for 202.96.105.101:
Packets: Sent = 1,Received = 1,Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 10ms,Maximum = 10ms,Average = 10ms
从上面我就可以知道从我的计算机到202.96.105.101一共通过了202.107.208.187 ,202.107.210.214,61.153.112.70,61.153.112.89,202.96.105.149,202.96.105.97这几个路由。
C:\>ping ds.internic.net
Pinging ds.internic.net [192.20.239.132] with 32 bytes of data:
Reply from 192.20.239.132: bytes=32 time=101ms TTL=243
Reply from 192.20.239.132: bytes=32 time=100ms TTL=243
Reply from 192.20.239.132: bytes=32 time=120ms TTL=243
Reply from 192.20.239.132: bytes=32 time=120ms TTL=243
C:\Documents and Settings\Administrator>ping -r 9 www.sina.com
Pinging libra.sina.com.cn [202.108.33.85] with 32 bytes of data:
Reply from 202.108.33.85: bytes=32 time=9ms TTL=55
Route: 10.0.0.1 ->
172.24.172.10 ->
202.106.48.2 ->
202.108.12.6 ->
202.106.48.6 ->
61.148.157.230 ->
61.148.157.229 ->
210.74.176.137 ->
202.108.33.1
ping -r 有时候也挺有用的,能看到ping路径
路由器一般都是一个入口一个出口
ping -r的结果只显示路由器的出口ip
tracert的结果只显示路由器的入口ip
所以这两个结果结合起来看,就能知道一个网络里的大概拓扑了
C:\Documents and Settings\Administrator>tracert www.sina.com
Tracing route to libra.sina.com.cn [202.108.33.96]
over a maximum of 30 hops:
1 1 ms 1 ms <1 ms 192.168.18.233
2 1 ms 1 ms 1 ms 10.0.0.2
3 <1 ms <1 ms <1 ms 10.1.1.1
4 <1 ms <1 ms <1 ms 172.24.149.129
5 1 ms <1 ms <1 ms zz-12-1-a8.bta.net.cn [202.108.12.1]
6 1 ms <1 ms 1 ms 202.106.48.5
7 21 ms 14 ms 1 ms 61.148.3.69
8 1 ms 1 ms 1 ms 61.148.143.30
9 2 ms 2 ms 1 ms 210.74.176.138
10 1 ms 1 ms 1 ms 202.108.33.96
C:\Documents and Settings\Administrator>ping -r 9 www.sina.com
Pinging libra.sina.com.cn [202.108.33.96] with 32 bytes of data:
Reply from 202.108.33.96: bytes=32 time=8ms TTL=55
Route: 10.0.0.1 ->
172.24.172.10 ->
202.106.48.2 ->
202.108.12.6 ->
202.106.48.6 ->
61.148.3.70 ->
61.148.143.29 ->
210.74.176.137 ->
202.108.33.1
ROUTER1:(192.168.18.233入口--10.0.0.1出口)
ROUTER2:(10.0.0.2入口--172.24.172.10出口)
ROUTER3:(10.1.1.1入口--202.106.48.2出口)
ROUTER4:(172.24.149.129入口--202.108.12.6出口)
……依此类推
还有个工具可以利用,pathping
C:\Documents and Settings\Administrator>pathping -n 202.108.12.6
Tracing route to 202.108.12.6 over a maximum of 30 hops
0 192.168.18.18
1 192.168.18.233
2 10.0.0.2
3 10.1.1.1
4 202.108.12.6
Computing statistics for 100 seconds...
Source to Here This Node/Link
Hop RTT Lost/Sent = Pct Lost/Sent = Pct Address
0 192.168.18.18
0/ 100 = 0% |
1 1ms 0/ 100 = 0% 0/ 100 = 0% 192.168.18.233
0/ 100 = 0% |
2 0ms 0/ 100 = 0% 0/ 100 = 0% 10.0.0.2
0/ 100 = 0% |
3 --- 100/ 100 =100% 100/ 100 =100% 10.1.1.1
0/ 100 = 0% |
4 0ms 0/ 100 = 0% 0/ 100 = 0% 202.108.12.6
Trace complete.
以上是对ping traceroute pathping的理解,如有补充的朋友在此基础上再完善一下







发表评论 评论 (3 个评论)