shell脚本批量追踪ip路由走向


shell脚本批量追踪ip路由走向

需求:

有大量ip地址需要追踪路由,查看是否经过(第三跳经过)192.168.23.2,如不经过,需要显示不能经过的ip

思路:

追踪路由用traceroute -m 4指定4跳即结束,由于到192.168.23.2不到4跳。所以追踪为4足够.

脚本如下:

  1. for IP in `cat $1`  
  2. do  
  3. traceroute -m 4 -n $IP|grep "192.168.23.2"  
  4. if [ "$?" != 0 ]  
  5. then  
  6. echo "$IP is not in area "  
  7. fi  
  8. done  #保存为traceroute.sh

使用方法:

sh tracerote.sh ip.txt

运行完毕,以上ip.txt的ip全部经过192.168.23.2

ip.txt 的ip如下

  1. 10.10.10.10  
  2. 211.182.23.5  
  3. 144.255.21.5  
  4. ……  
  5. N多IP,在此不列举 

相关内容