Skip to content

Instantly share code, notes, and snippets.

@phenotypic
Last active May 11, 2019 22:38
Show Gist options
  • Save phenotypic/6900aae9f86cd15ac1bbe163702c3717 to your computer and use it in GitHub Desktop.
Save phenotypic/6900aae9f86cd15ac1bbe163702c3717 to your computer and use it in GitHub Desktop.
Simple script to check if your NodeMCUs are reachable on your network
#! /bin/bash
#DESCRIPTION: Pings all the IPs in the list and reports whether or not they are reachable
GREEN='\033[1;32m'
RED='\033[1;31m'
BLUE='\033[1;34m'
THICK='\033[1;37m' #For white backgrounds, use: THICK='\033[1;30m'
NC='\033[0m'
#Fill with your NodeMCUs (no line spaces)
#Format: <nickname>~<IP address>
LIST="Gate~192.168.1.33
Garage~192.168.1.34
Thermometer~192.168.1.35
RGB Light~192.168.1.36"
LISTLENGTH="$( echo "$LIST" | wc -l | tr -dc '0-9' )"
printf "${BLUE}[*] ${NC}Checking ${THICK}$LISTLENGTH${NC} NodeMCUs...\n"
COUNT=0
while read LINE; do
NAME="$( echo "$LINE" | sed 's/~.*//' )"
ADDRESS="$( echo "$LINE" | sed -n -e "s/^.*~//p" )"
ping -c1 -W1 -q $ADDRESS &>/dev/null
STATUS=$( echo $? )
if [[ $STATUS == 0 ]] ; then
printf "\n${GREEN}[*] ${THICK}$NAME${NC}"
COUNT=$(($COUNT + 1))
else
printf "\n${RED}[!] ${THICK}$NAME${NC} ($ADDRESS)"
fi
done <<< "$LIST"
if [ "$COUNT" == "$LISTLENGTH" ]; then
printf "\n\n${BLUE}[*] ${NC}All reachable! (${THICK}$COUNT/$LISTLENGTH${NC})\n"
else
printf "\n\n${RED}[*] ${THICK}$COUNT/$LISTLENGTH${NC} reachable\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment