Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.


Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.


Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.


Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Monitoring, Networking

Verifying SNMP Connectivity on Multiple Hosts

Submitted by on December 19, 2019 – 9:50 pm

I needed to check if SNMP was accessible on whatever live servers that existed in a particular subnet. Here’s a quick script to do this.

You will need to specify subnet information and the SNMP community string. The script will use nmap to find live hosts and will use snmpwalk running via xargs to query multiple hosts at once. The end result should look something like this:       no       no  ncc1701.jedi.local  yes

And here’s the script

subnet=; subnetmask=24
commstr="vvrblfcctcbhrgbhincdggrjhb"; export commstr
threads=$(grep -c processor /proc/cpuinfo) && (( threads = threads * 10 )) || threads=12
snmpcheck() {
  echo -ne "\t$(host -4 -t A -W1 -s  2>/dev/null | awk '{print $NF}' | \
  sed -r "s/.*DOMAIN.*//g")\t$(snmpwalk -c ${commstr} -v 2c  2>/dev/null | head -1 | wc -l)\n" | \
  awk '$3!=1 {print $1,$2,"no";next}; $3=1{print $1,$2,"yes";next};{print $0}'
} && export -f snmpcheck
nmap -sn ${subnet}/${subnetmask} -oG - | awk '$4=="Status:" && $5=="Up" {print $2}' | \
xargs -n1 -P${threads} bash -c 'snmpcheck "$@"' _ | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | column -t


Print Friendly, PDF & Email

Leave a Reply