Last active
October 7, 2024 19:04
-
-
Save eldaroid/8e6158980c327db1c87fec86f8f8eecd to your computer and use it in GitHub Desktop.
RU: Скрипт проверяет доступность IP-адресов в указанном диапазоне. Он пингует каждый IP-адрес в сети 192.168.0.x и выводит сообщение, если адрес доступен. EN: The script checks the availability of IP addresses in the specified range. It pings each IP address in the 192.168.0.x network and displays a message if the address is available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <number_of_ips>" | |
exit 1 | |
fi | |
if ! [[ $1 =~ ^[0-9]+$ ]] || [ $1 -lt 0 ] || [ $1 -gt 255 ]; then | |
echo "Error: The argument must be a number in the range from 0 to 255." | |
exit 1 | |
fi | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
NET="192.168.0." | |
LIMIT=$1 | |
for ((i=0; i<LIMIT; i++)) | |
do | |
ADR="${NET}${i}" | |
echo "Pinging $ADR..." | |
if ping -c 1 -W 1 $ADR &> /dev/null | |
then | |
echo -e "${GREEN}$ADR is alive${NC}\n" | |
else | |
echo -e "${RED}$ADR is not reachable${NC}\n" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same on Windows: