Turning POE on and off on the Cisco 3750 via SNMP

I recently had a requirement to be able to turn the POE power off / on on specific ports on a remote c3750 POE switch in order to reboot devices that kept crashing.

I had been remotely logging in via SSH and doing the following to turn the power off on port 1:


configure terminal
interface FastEthernet1/0/1
power inline never
exit
exit

Then after a few seconds:


configure terminal
interface FastEhernet1/0/1
no power inline never
exit
exit

This got to be a real nuisance so I looked for something that I could script, SNMP seemed the logical choice. The first step is to configure a R/W community string on the switch:


configure terminal
snmp-server community MyCommunityString rw
exit
write memory

After a bit of digging I found the appropriate OID by using snmpwalk (here we assume my switch is on IP address 1.2.3.4):


snmpwalk -v2c -On -c MyCommunityString 1.2.3.4 1.3.6.1.2.1.105.1.1.1.3.1

My 24 port switch returned the following:

.1.3.6.1.2.1.105.1.1.1.3.1.3 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.4 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.5 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.6 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.7 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.8 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.9 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.10 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.11 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.12 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.13 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.14 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.15 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.16 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.17 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.18 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.19 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.20 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.21 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.22 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.23 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.24 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.25 = INTEGER: 1
.1.3.6.1.2.1.105.1.1.1.3.1.26 = INTEGER: 1

The port number go from .3 to .26 corresponding to the 24 FastEthernet ports.

The integer values need to be 1 to enable POE and 2 to disable it.

So using snmpset we can turn the power on port 1 off:


snmpset -v2c -c MyCommunityString 1.2.3.4 1.3.6.1.2.1.105.1.1.1.3.1.7 i 2

and back on again:


snmpset -v2c -c MyCommunityString 1.2.3.4 1.3.6.1.2.1.105.1.1.1.3.1.7 i 1

That’s it! Simple really. Adding the commands to a script I will leave to the imagination of the reader…