通过fping快速检验多个网络是否通

作者:吴业亮
博客:wuyeliang.blog.csdn.net

常规做法,通过ping验证网络
脚本test.sh如下

#!/bin/bash
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
for v  in {1..200}
do
    ping -c 3 -W 3 192.168.8.${v} >/dev/null
    if [ $?  -ne 0 ]
    then
		echo "192.168.8.${v} is  unreachable >>unreachable.log 
    fi
done

参数说明:

-c ping次数
-w 每次ping超时时间,单位秒

测试200个IP需要的时间9min多

time  bash test.sh
real	9m41.884s
user	0m0.225s
sys	0m0.734s

快速验证方法

#!/bin/bash
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
LIST=`echo 192.168.8.{1..200}`
time  fping ${LIST}

测试时间20s左右:

time  fping ${LIST} 
real	0m20.271s
user	0m0.017s
sys	0m0.104s

参数说明

-a

Lists targets that responded

显示可ping通的目标

-A

Lists targets by address instead of hostname

将目标以ip地址的形式显示

-b 

Sends  bytes of data per ICMP packet (default 56)

ping 数据包的大小。(默认为56)

-B 

Tells fping to wait  times longer for a reply after each successive failed request (default 1.5)

设置指数反馈因子到f

-c 

Number of Pings to send to each target (default 1)

ping每个目标的次数 (默认为1)

-C 

Same as above but prints additional statistics for each host

同-c,返回的结果为冗长格式

-e

Displays elapsed time on return packets

显示返回数据包所费时间

-f 

Reads the target list from  (use "-" for standard input) (only if no -g specified)

从文件获取目标列表( - 表示从标准输入)(不能与 -g 同时使用)

-g

Tells fping to generate a target list by specifying the start and end address (ex. ./fping -g 192.168.1.0 192.168.1.255) or an IP/subnet mask (ex. ./fping -g 192.168.1.0/24)

通过指定开始和结束地址来生成目标列表(例如:./fping –g 192.168.1.0 192.168.1.255)或者一个IP/掩码形式(例如:./fping –g 192.168.1.0/24)

-i 

Interval (in milliseconds) to wait between Pings (default 25)

设置ip的TTL值 (生存时间)

-l

Sends Pings forever

循环发送ping

-m

Pings multiple interfaces on target host

ping目标主机的多个网口

-n

Displays targets by name (-d is equivalent)

将目标以主机名或域名显示(等价于 -d )

-p 

Interval (in milliseconds) between Pings to an individual target (in looping and counting modes, default 1000)

对同一个目标的ping包间隔(毫秒) (在循环和统计模式中,默认为1000)

-q

Doesn't show per-target/per-Ping results

安静模式(不显示每个目标或每个ping的结果)

-Q 

Same as -q, but show summary every  seconds

同-q, 但是每n秒显示信息概要

-r 

When a host doesn't respond, retries the host  times (default 3)

当ping失败时,最大重试次数(默认为3次)

-s

Displays summary statistics

打印最后的统计数据

-t 

Timeout (in milliseconds) for individual targets (default 500)

单个目标的超时时间(毫秒)(默认500)

-u

Displays targets that are unreachable

显示不可到达的目标

-v

Displays version number

显示版本号

你可能感兴趣的:(linux,fping,快速,ping,批量)