Commit 1f1009e7 authored by aghead.asaad's avatar aghead.asaad

Exercise3

parent 0c71dc00
#!/bin/bash
# alive2.sh
# Checks to see if a range of IP addresses are alive
# Input should be in the format alive2.sh 192.168.1.7-192.168.1.123
# Validate the input format
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
start=$(echo $1 | cut -d'-' -f1 | cut -d'.' -f4)
end=$(echo $1 | cut -d'-' -f2 | cut -d'.' -f4)
# Iterate through IP addresses
for ((n=start; n<=end; n++)); do
host=$(echo $1 | cut -d'-' -f1 | cut -d'.' -f1-3).$n
ping -c2 $host &> /dev/null
if [ $? = 0 ]; then
echo "$host is UP"
else
echo "$host is DOWN"
fi
done
else
echo "Invalid input format. Please use the format alive2.sh 192.168.1.7-192.168.1.123"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment