Linux常用网络工具:fping主机扫描

fping 介绍

Linux下有很多强大网络扫描工具,网络扫描工具可以分为:主机扫描、主机服务扫描、路由扫描等。

fping是一个主机扫描工具,相比于ping工具它可以批量扫描主机。

fping完全不同于ping,因为您可以在命令行上定义任意数量的主机,或者指定包含要ping的IP地址或主机列表的文件。

例如,使用fping,我们可以指定完整的网络范围( 192.168.0.1/24 )。
它会向主机发送Fping请求,并以循环方式移动到另一个目标主机。 与ping不同,Fping基本上用于编写脚本。

访问fping 官方网站:http://fping.org下载最新版安装程序
官网.png

一、编译及安装

安装可以使用yum安装或者源码安装

yum 安装命令:

yum install fping
非root用户可使用sudo或者切换到root用户安装
sudo yum install fping

源码安装

[root@node1 ~]# wget http://fping.org/dist/fping-4.2.tar.gz
[root@node1 ~]# ll fping-4.2.tar.gz 
-rw-r--r--. 1 root root 171409 2月  20 05:05 fping-4.2.tar.gz
[root@node1 ~]# tar xf fping-4.2.tar.gz && cd fping-4.2
[root@node1 fping-4.2]# ./configure && make && make install

f拼.png
查看安装版本

fping -v

VERSION.png

二、使用示例
2.1 ping多个主机
[root@node1 fping-4.2]# fping 172.31.8.13 172.31.8.107 172.31.8.75 172.31.8.3
172.31.8.13 is alive    ---主机活动
172.31.8.107 is alive
172.31.8.75 is alive
172.31.8.75 is unreachable  --- 主机不可用
[root@node1 fping-4.2]# 
2.2 ping IP地址范围

以下命令将接收ping的IP范围并输出以下内容,我们将响应请求发送到该范围内的IP并获得我们想要信息。结束后还显示累积结果

[root@node1 fping-4.2]# fping -s -g 172.31.8.1 172.31.8.10
172.31.8.1 is alive
172.31.8.3 is alive
172.31.8.5 is alive
172.31.8.8 is alive
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.2
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.2
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.2
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.2
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.4
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.4
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.4
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.4
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.6
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.6
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.6
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.6
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.7
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.7
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.7
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.7
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.9
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.9
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.9
ICMP Host Unreachable from 172.31.8.8 for ICMP Echo sent to 172.31.8.9
172.31.8.2 is unreachable
172.31.8.4 is unreachable
172.31.8.6 is unreachable
172.31.8.7 is unreachable
172.31.8.9 is unreachable
172.31.8.10 is unreachable

    10 targets
    4 alive
    6 unreachable
    0 unknown addresses

    6 timeouts (waiting for response)
    28 ICMP Echos sent
    4 ICMP Echo Replies received
    20 other ICMP received

0.04 ms (min round trip time)
0.73 ms (avg round trip time)
1.15 ms (max round trip time)
        4.164 sec (elapsed real time)

[root@node1 fping-4.2]# 
2.3 ping整个IP段,并重复一次

测试.png

2.4 从文件中读取IP信息,执行ping

测试2.png

三、查看帮助信息
[root@node1 fping-4.2]# fping -help

Usage: fping [options] [targets...]
用法:fping [选项] [ping的目标]
-a         show targets that are alive
            显示可ping通的目标
-A         show targets by address
            将目标以ip地址的形式显示
-b n       amount of ping data to send, in bytes (default 56)
            ping 数据包的大小。(默认为56)
-B f       set exponential backoff factor to f
            设置指数反馈因子到f
-c n       count of pings to send to each target (default 1)
                ping每个目标的次数 (默认为1)
-C n       same as -c, report results in verbose format
                同-c, 返回的结果为冗长格式
-e         show elapsed time on return packets
                显示返回数据包所费时间
-f file    read list of targets from a file ( - means stdin) (only if no -g specified)
            从文件获取目标列表( - 表示从标准输入)(不能与 -g 同时使用)
-g         generate target list (only if no -f specified)
            生成目标列表(不能与 -f 同时使用)
                (specify the start and end IP in the target list, or supply a IP netmask)
                (ex. fping -g 192.168.1.0 192.168.1.255 or fping -g 192.168.1.0/24)
                (可指定目标的开始和结束IP, 或者提供ip的子网掩码)
                (例:fping -g 192.168.1.0 192.168.1.255 或 fping -g 192.168.1.0/24)
-H n       Set the IP TTL value (Time To Live hops)
                设置ip的TTL值 (生存时间)
-i n       interval between sending ping packets (in millisec) (default 25)
            ping包之间的间隔(单位:毫秒)(默认25)
-l         loop sending pings forever
            循环发送ping
-m         ping multiple interfaces on target host
                ping目标主机的多个网口
-n         show targets by name (-d is equivalent)
                将目标以主机名或域名显示(等价于 -d )
-p n       interval between ping packets to one target (in millisec)
                对同一个目标的ping包间隔(毫秒)
                (in looping and counting modes, default 1000)
                (在循环和统计模式中,默认为1000)
-q         quiet (don't show per-target/per-ping results)
            安静模式(不显示每个目标或每个ping的结果)
-Q n       same as -q, but show summary every n seconds
            同-q, 但是每n秒显示信息概要
-r n       number of retries (default 3)
            当ping失败时,最大重试次数(默认为3次)
-s         print final stats
            打印最后的统计数据
-I if      bind to a particular interface
            绑定到特定的网卡
-S addr    set source address
                设置源ip地址
-t n       individual target initial timeout (in millisec) (default 500)
            单个目标的超时时间(毫秒)(默认500)
-T n       ignored (for compatibility with fping 2.4)
                请忽略(为兼容fping 2.4)
-u         show targets that are unreachable
                显示不可到达的目标
-O n       set the type of service (tos) flag on the ICMP packets
                在icmp包中设置tos(服务类型)
-v         show version
                显示版本号
targets    list of targets to check (if no -f specified)
                需要ping的目标列表(不能和 -f 同时使用)
-h              show this page
                显示本帮助页

-------------本文结束感谢您的阅读-------------
请我吃辣条
0%