Traceroute(路由追踪)

Traceroute的实现有两种:

基于UDP实现

traceroute向目的主机发送一系列普通IP数据报,但每个数据报携带一个不可达UDP端口号的UDP报文,TTL分别为1,2,3...TTL过期时,路由器丢弃数据报并发送ICMP告警报文给源主机。如何得知何时停止发送UDP报文?目的主机会发送端口不可达的ICMP报文,中间路由器则发送ICMP超时报文。

基于ICMP实现

直接发送一个ICMP回显请求(echo request)数据包,服务器在收到回显请求的时候会向客户端发送一个ICMP回显应答(echo reply)数据包,在这之后的流程还是跟第一种方案一样。这样就避免了我们的traceroute数据包被服务器的防火墙策略墙掉。 

In Unix/Linux, the source sends a series of UDP packets to the target destination using an unlikely destination port number;

in Windows, the source sends a series of ICMP packets to the target destination.

For both operating systems, the program sends the first packet with TTL=1, the second packet with TTL=2, and so on.

在Windows系统中也有traceroute程序,它的名字叫做tracerttracert就是用基于这种方法采用ping来实现的。

相关实现代码见以下参考链接

摘自Traceroute(路由追踪)的原理及实现

 

附:

ICMP与IP同属于网络层,但同TCP, UDP类似,被IP封装。

ICMP虽然被IP封装,但不代表ICMP属于传输层。

网络层的层次并不是通过A封装了B,A就在B的下一层来区分的。

posted @ 2018-10-24 00:40  我在地狱  阅读(1160)  评论(0编辑  收藏  举报