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 print "$me: Usage: $me { count }"
23 print "\twhere count = number of times to ping a machine before
25 print "\tthe machine to be not responding (default count = 2)."
33 # Attempt to determine the OS. First attempt to remsh to the machine and
34 # do a uname(1). This assumes Unix. We are unable to remsh then we'll
35 # assume that it's a PC (it could also be a line printer or any other of
36 # a number of network pingable devices!)
37 os=$(remsh $machine -n uname 2>&1)
39 # We're gonna make some guesses here...
40 if [[ "$os" = "HP-UX" ||
41 "$os" = "Linux" ]]; then
43 elif [[ "$os" = *Lost\ connection ]]; then
44 os="Linux? (Lost connection)"
45 elif [[ "$os" = *Permission\ denied. ]]; then
46 os="Linux? (Permission denied)"
47 elif [[ "$os" = *Login\ incorrect ]]; then
48 os="HP-UX? (Login incorrect)"
49 elif [[ "$os" = *Connection\ refused ]]; then
50 os="NT? (Connection refused)"
60 elif [ $# -gt 1 ]; then
66 if [ "$TERM" = "dtterm" -o -z DTTERM ]; then
67 export normal="$esc[39m"
69 export green="$esc[32m"
70 elif [ "$TERM" = "hp" -o "$TERM" = "hpterm" ]; then
71 export normal="$esc&d@$esc&v0S"
73 export green="$esc&v2S"
77 print " Machine\t\t IP\tState\t OS"
78 print - "-----------------------\t-------------\t-----\t-------"
80 subnet=${subnet:-15.28}
81 integer starting_subnet_octect=${starting_subnet_octect:-96}
82 integer ending_subnet_octect=${ending_subnet_octect:-103}
83 integer subnet_octect=starting_subnet_octect
84 integer starting_octect=${starting_octect:-0}
85 integer ending_octect=${ending_octect:-255}
86 integer octect=$starting_octect
88 while [ $subnet_octect -le $ending_subnet_octect ]; do
89 while [ $octect -le $ending_octect ]; do
90 ip=$subnet.$subnet_octect.$octect
92 nslookup $ip 2>&1 | grep Non-exist > /dev/null 2>&1
94 machine=$(nslookup $ip | grep Name: | awk '{print $2}' | cut -f1 -d.)
97 if [ ${#machine} -lt 8 ]; then
99 elif [ ${#machine} -lt 16 ]; then
103 ping_result=$(ping $ip -n $count | tail -1 | grep "100% packet loss")
104 if [ -z "$ping_result" -eq 0 ]; then
105 print "${green}UP${normal}\t\c"
109 print "${red}DOWN${normal}\tUnknown"
113 let subnet_octect=subnet_octect+1
114 let octect=starting_octect