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.