Ping range of IP addresses in parallel with fping

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

fping is a program which uses the Internet Control Message Protocol (ICMP) echo request to determine if a host is up. fping is different from ping in that you can specify any number of hosts on the command line, or specify a file containing the lists of hosts to ping. Instead of trying one host until it timeouts or replies, fping will send out a ping packet and move on to the next host in a round-robin fashion. If a host replies, it is noted and removed from the list of hosts to check. If a host does not respond within a certain time limit and/or retry limit it will be considered unreachable.

Basically fping is meant to be used in shell scripts and its output is easy to parse. This command can be very useful to when you have to scan whole network for alive or unreachable hosts. In case of usage regular ping command you’ll have to write shell script and parse each hosts icmp replies but fping can do the same in one line:

To scan range of IP addresses from 192.168.0.1 to 192.168.0.9 just run:
sudo fping -s -g 192.168.0.1 192.168.0.9 -r 1

That will output:

192.168.0.1 is alive
192.168.0.7 is alive
192.168.0.2 is unreachable
192.168.0.3 is unreachable
192.168.0.4 is unreachable
192.168.0.5 is unreachable
192.168.0.6 is unreachable
192.168.0.8 is unreachable
192.168.0.9 is unreachable

9 targets
2 alive
7 unreachable
0 unknown addresses

14 timeouts (waiting for response)
16 ICMP Echos sent
2 ICMP Echo Replies received
0 other ICMP received

0.05 ms (min round trip time)
0.44 ms (avg round trip time)
0.84 ms (max round trip time)
2.183 sec (elapsed real time)

In order to scan /24 network (254 hosts) and show only alive hosts the following command can be used:

sudo fping -a -q -g 192.168.0.0/24

 
 
» You might also be interested in the following articles:
Combined traceroute and ping utility (mtr)
Testing system validity
Secure shell (ssh) session timeout
ptunnel: send/receive TCP traffic via ICMP reliably
Linux networking stack understanding



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!


22 Responses to “Ping range of IP addresses in parallel with fping”


  1. 1 Kalyan

    Hi Dudu

    Please help how to ping list of hosts specified in a file.if possible can u give it in a script.

    Thanks

  2. 2 artiomix

    Hi Kalyan,

    You can try this:

    cat /tmp/ips | xargs -n 1 ping -c 10

    this will ping ip addresses listed in /tmp/ips with 10 packets each.

    P.S. viper-laptop:~$ cat /tmp/ips
    64.233.187.99
    216.239.47.1
    4.2.2.4

  3. 3 pellgarlic

    from “man fping” -

    -f Read list of targets from a file. This option can only be used by the root user. Regular users should pipe in the file via stdin:

    % fping

  4. 4 pellgarlic

    ok…. obviously i need to put tags in there :0 i'll try again:

    -f Read list of targets from a file. This option can only be used by the root user. Regu?
    lar users should pipe in the file via stdin:

    % fping

    hope that's clearer...

  5. 5 pellgarlic

    dammit! ok - type “man fping” and look for the “-f Read list of targets from a file….” bit. it’s not showing it all when i paste in in here, dont know how too fix that, sorry.

  6. 6 pellgarlic

    ok, one last try -

    -f Read list of targets from a file. This option can only be used by the root user. Regular users should pipe in the file via stdin:

    % fping

    if that hasn worked, i'm leaving it alone :)

  7. 7 artiomix

    Thanks pellgarlic!

    Yes, here is example of usage fping:

    fping < /tmp/ips

    That will ping range of IP listed in /tmp/ips IN PARALLEL, by the way:

    viper-laptop:~$ cat /tmp/ips
    64.233.187.99
    216.239.47.1
    4.2.2.4

    Hope it helps! :)

  8. 8 pellgarlic

    nope - it’s cutting bits out - read the “man” page for the full info

  9. 9 pellgarlic

    ahh… artiomix - how did you get the “less than” arrow to show up? it kept cutting it out for me :)

  10. 10 artiomix

    Just cover your text with <code></code> tags :)

  11. 11 artiomix

    Oh yeah, it works:

    sudo fping -f /tmp/ips
    4.2.2.4 is alive
    64.233.187.99 is alive
    216.239.47.1 is alive

    :D

  12. 12 pellgarlic

    cool :) i tried the tags, but it kept cutting out bits anyway - nevermind - you got the important info up there, and that’s what matters.

    another victory for the www! knowledge is power! :D

  13. 13 Kalyan

    sudo fping -f /tmp/ips
    4.2.2.4 is alive
    64.233.187.99 is alive
    216.239.47.1 is alive

    Hi pellgarlic

    Thanks for all the above comments,i followed the above with little modification to suit my need and it’s working fine.

    cheers

  14. 14 Kalyan

    Hi artiomix

    Thanks!

    Cheers.

  15. 15 artiomix

    Hi Kalyan, you’re more than welcome! :)

  16. 16 Kalyan

    Hi artiomix,pellgarlic

    I am using below script my problem is here,i put this script in crontab to run daily 3 times and move the file “stb” to desktop of another system in the network by using ” mv /root/stb /root/livestb.`date +%d%I%M` && scp livestb.* root@192.168.0.20:/root/Desktop” as a script but final output on the desktop is empty file.

    #!/bin/sh
    #
    #Script to ping all the hosts
    #
    rm /root/livestb.* && echo “File removed successfully” #To remove previously run file
    fping /root/stb
    echo ” ***completed*** ”
    exit 0

    Please can u correct me.

    thanks in advance.

  17. 17 pellgarlic

    hi kalyan, what you’re missing is the redirection… you would need to replace “fping /root/stb” with something like this:

    “fping -f /file/with/list/of/ips/to/ping > results/of/fping”

    (i.e. - you need 2 files -

    1 - the list of ip addresses to ping
    2 - the output of the fping command)

  18. 18 pellgarlic

    so, maybe something like this:

    fping -f /root/stb > /root/livestb.`date +%d%I%M`

  19. 19 pellgarlic

    it seems that you may be confusing the file that fping reads from, with a file you want to have the output stored in -

    to have fping read from a file, do this:

    fping -f /path/to/file

    to save the ouput of fping to a file, do this:

    fping -f /path/to/file > /path/to/save/to

    (the “>” can be used to redirect the terminal output of any command-line command to a file)

  20. 20 alvaro

    Personally, i think it’s better to use
    rm -rf /root/livestb.*

    than

    rm /root/livestb.* && echo "File removed successfully"

    By the way, i recommend you not to make scripts with root powers (uhm, quite dangerous).

    Thanks

  21. 21 kalyan

    Hi friends,

    Thanx for all your replys.

    cheers,
    kalyan.

  22. 22 hozefa

    Can you guys help me install fping so that I can run it through Cygwin on a windows desktop.

    Thanks

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››