Jun 182015
 

I recently had to verify a whole bunch of servers were responding to SNMP and had the correct DNS reverse look ups in Active Directory.
I used this little script so that it would ask me for an IP address and then do a ping, and then if a server was reachable over ICMP, a nslookup if a server responded to the SNMP Query for the system name.


#!/bin/bash

snmpPoll() {
icmp=$(ping -c 1 $1)
if [[ $? -eq 0 ]]; then
echo "$1 is pinging..."
nsout=$(nslookup $1 | awk -F 'name = ' ' { printf $2 } ')
echo "IP resolves to $nsout"
output=$(snmpwalk -v 2c -c R34d0N1y $1 .1.3.6.1.2.1.1.5)
if [[ $? -eq 0 ]]; then
echo $output
hostname=$(nslookup $(echo $output | awk -F ': ' ' { print $2 } '))
echo $hostname
else
echo $output
echo "not performing nslookup"
fi
else
echo "$1 not responding to ping"
fi
}

prompt() {
read -p "$1"" : " val
snmpPoll $val
}

while true; do prompt "IP Address"; done

Thought I’d post it in case it came in useful for anyone else.
This could be adapted to work off a file full of IP addresses or host names very easily, but for my purposes I was manually entering in IP addresses.

Share

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.