Files
2026-09-14 12:43:38 +02:00

43 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
if [ "$2" == "-c" ];then
blue="\e[34m"
red="\e[31m"
norm="\e[0m"
else
blue=""
red=""
norm=""
fi
declare -a hosts=("serverhost" "workhost" "quiethost" "localhost")
if [ "$#" -eq 0 ];then
printf "Arguments: hosts, netw\n"
fi
if [ "$1" == "hosts" ];then
for host in "${hosts[@]}"; do
ping -c 2 -W 1 $host > /dev/null
if [ $? -eq 0 ]; then
printf "%s\t\t[$blue UP$norm ]\n" "$host" | sed "s/localhost/$(hostname)/g"
else
printf "%s\t\t[$red DOWN$norm ]\n" "$host"
fi
done
elif [ "$1" == "netw" ];then
if [ "$(ifconfig | grep -A2 eth0 | grep inet)" != "" ]; then
if="eth0"
elif [ "$(ifconfig | grep -A2 wlan0 | grep inet)" != "" ]; then
if="wlan0"
fi
#netw="$(ifconfig $if | grep -m1 -o -P '(?<=inet ).*(?= netmask)' | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.')"
netw="$( ifconfig $if | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.' | grep -m1 -v 255)"
for i in {1..254}; do
ping -c 1 -W 1 $netw$i > /dev/null
if [ $? -eq 0 ]; then
# hostname="$(ssh 10.0.0.$i hostname)"
# if [ ! $? -eq 0 ]; then
hostname="$(nbtscan 10.0.0.$i | grep -A1 "\-\-\-\-\-" | sed 's/ */ /g' | cut -d' ' -f2 | grep '[A-Za-z]')"
# fi
printf "10.0.0.%s\t[$blue UP$norm ]\t%s\n" "$i" "$hostname"
fi
done
fi