you can use it for example, to find out the switch names using snmp

-----------------------------------------
the script to check all devices in ip-range from 192.168.2.1-254
> the output will be:
192.168.2.1;switchname1
192.168.2.2;switchname2
....
------------------------------------------
#!/bin/bash

community="public" # Replace with your actual community string
oid="1.3.6.1.2.1.1.5.0" # OID for sysName

for ((i=1; i<=254; i++)); do
current_ip="192.168.2.$i"
result=$(snmpget -v 2c -c "$community" "$current_ip" "$oid" 2>/dev/null)

if [ $? -eq 0 ]; then
name=$(echo "$result" | awk '{print $NF}' | tr -d '"' )
echo "$current_ip;$name"
else
echo "Failed to retrieve data from $current_ip"
fi
done

computer2know :: thank you for your visit :: have a nice day :: © 2024