bash script to test network connection - please help

I want to test if my host can connect to any of the following 10 hosts (192.168.1.0 to 192.168.1.9)

I didnt know which command i should use, so i chose ping. (i wonder if i should use tracepath or sth else)

my code is the following:

#!/bin/bash
clear
firstPart="192.168.1"
maxNum="9"

for (( lastPart=0; lastPart<=$maxNum; lastPart++ ))
do
    ipAddr="$firstPart.$lastPart"

    if ping -c 1 -W 1 $ipAddr
    then
        echo "This comp can be connected."
    fi
done

The problem is on this line "ping -c 1 -W 1 $ipAddr"
It would take 10 seconds to check the network connection in the worse case. (if all hosts are not reachable from my host), which is so long.

So i am wondering, if there another approach to accomplish the same thing? Is that possible to use tracepath instead of ping?

Thanks in advance.

With what protocole do you establish a communication with these hosts? ssh? http?

You may also want to check a specific port on the targeted hosts instead of sending ICMP packets to the hole host.

Hey Shadow Boi,

You should use lower case w (deadline) instead of upper case W (timeout).
I'm doing the same check with a set of 40 machines and it never last more than 40 seconds (in the worst case).

Hope this helps
Santiago