How To Check if an IP is Available or Not in Bash
A quick trick I use is ‘ping’ command. PING will return 0 on success and 1 or above on failure while using it with -c 1 (Means only one ICMP packet). That makes it useful to use with a if condition shell code as following:
if ping -c 1 -w 5 192.168.2.1 >/dev/null
echo "IP Available"
echo "IP Not Available"