2 ################################################################################
5 # RCS: $Header: pingnet,v 1.3 98/03/04 00:42:49 defaria Exp $
6 # Description: A script to ping all machines and report status. This script
7 # uses /etc/hosts and selects only machines in the IP range of
8 # 15.0.96.x to 15.0.99.x.
9 # Author: Andrew DeFaria <Andrew@DeFaria.com>
10 # Created: Sat Oct 26 10:04:28 PDT 1996
11 # Modified: Sat Oct 26 12:05:26 PDT 1996 Andrew DeFaria <defaria@cup.hp.com>
12 # Parameters: count (default 2): number of times to ping a machine before
13 # considering it not responding.
14 # Language: Korn Shell
16 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
18 ################################################################################
22 echo -e "$me: Usage: $me { count }"
23 echo -e "\twhere count = number of times to ping a machine before
25 echo -e "\tthe machine to be not responding (default count = 2)."
36 # Attempt to determine the OS. First attempt to remsh to the machine and
37 # do a uname(1). This assumes Unix. We are unable to remsh then we'll
38 # assume that it's a PC (it could also be a line printer or any other of
39 # a number of network pingable devices!)
40 os=$(rsh $machine -n uname 2>&1)
42 # We're gonna make some guesses here...
43 if [[ "$os" = "HP-UX" ||
44 "$os" = "Linux" ]]; then
46 elif [[ "$os" = *Lost\ connection ]]; then
47 os="Linux? (Lost connection)"
48 elif [[ "$os" = *Permission\ denied. ]]; then
49 os="Linux? (Permission denied)"
50 elif [[ "$os" = *Login\ incorrect ]]; then
51 os="HP-UX? (Login incorrect)"
52 elif [[ "$os" = *Connection\ refused ]]; then
53 os="NT? (Connection refused)"
63 elif [ $# -gt 1 ]; then
69 if [ "$TERM" = "dtterm" -o -z DTTERM ]; then
70 export normal="$esc[39m"
72 export green="$esc[32m"
73 elif [ "$TERM" = "hp" -o "$TERM" = "hpterm" ]; then
74 export normal="$esc&d@$esc&v0S"
76 export green="$esc&v2S"
80 echo -e " Machine\t\t IP\tState\t OS"
81 echo -e "-----------------------\t-------------\t-----\t-------"
83 subnet=${subnet:-192.168}
84 declare -i starting_subnet_octect=${starting_subnet_octect:-0}
85 declare -i ending_subnet_octect=${ending_subnet_octect:-0}
86 declare -i subnet_octect=starting_subnet_octect
87 declare -i starting_octect=${starting_octect:-0}
88 declare -i ending_octect=${ending_octect:-255}
89 declare -i octect=$starting_octect
91 while [ $subnet_octect -le $ending_subnet_octect ]; do
92 while [ $octect -le $ending_octect ]; do
93 ip=$subnet.$subnet_octect.$octect
95 nslookup $ip 2>&1 | grep Non-exist > /dev/null 2>&1
97 machine=$(nslookup $ip | grep Name: | awk '{print $2}' | cut -f1 -d.)
99 echo -e "$machine\t\c"
100 if [ ${#machine} -lt 8 ]; then
102 elif [ ${#machine} -lt 16 ]; then
106 ping_result=$(ping $ip -n $count | tail -1 | grep "100% loss")
107 if [ -z "$ping_result" ]; then
108 echo -e "${green}UP${normal}\t\c"
112 echo -e "${red}DOWN${normal}\tUnknown"
116 let subnet_octect=subnet_octect+1
117 let octect=starting_octect