How can I enable/disable ports in Cisco Catalyst 2960 with C#?

24,200

Solution 1

I know three methods (I am most fond of the first):

Option 1:
A common way to approach something like this is automated telnet (or automated ssh) to send the appropriate commands. IOS is pretty standardized for the most part and works quite well this way-
TCL's Expect package is perfect for this kind of thing... I imagine there is a C# implementation.

This works best if you are already familiar with IOS syntax.

Option 2:
This is probably what you want:
IF-MIB::ifAdminStatus is writable via SNMP (Here is an example using NET-SNMP):

Interface UP:
snmpset -v1 -c community hostname IF-MIB::ifAdminStatus.interface i 1

Interface DOWN:
snmpset -v1 -c community hostname IF-MIB::ifAdminStatus.interface i 2

(Where 'interface' is a digit that represents a interface, the value is available in the same MIB- do a walk on 1.3.6.1.2.1.2.2.1.2 to find the interface values and descriptions.)

(Again there will likely be a C# implementation of snmpset you can leverage... and you must configure the SNMP communities on the device beforehand.)

Option 3:
It is possible to use SNMP to trigger an upload or download of config via a TFTP server.
This is sometimes used in this sequence:
1. download running config
2. alter that config
3. upload config
4. copy the uploaded config to the running config (overwrites what's active on the device)

Solution 2

I have found for several POE switches ( cisco and zyxel) that the snmp string to manipulate POE state is

SNMPv2-SMI::mib-2.105.1.1.1.3.1.x with x being the desired port ( for a 8 port switch 1~8 for 24 port switch 1~24 )

the mentioned IF-MIB::ifAdminStatus.interface act only for the enable/disable port - but the main goal is to reset or reduce power cost for over night /weekend in an environment with tens/hundreds of Access Points / VoIP phones this can save a lot of energy

the command to stop POE on port is

snmpset -v 2c -c setcomunity host SNMPv2-SMI::mib-2.105.1.1.1.3.1.x i 2

the command to start POE on port is

snmpset -v 2c -c setcomunity host SNMPv2-SMI::mib-2.105.1.1.1.3.1.x i 1

if you use version 3 you'll need authentication also

Share:
24,200
tingfungc
Author by

tingfungc

Updated on September 20, 2020

Comments

  • tingfungc
    tingfungc over 3 years

    I am a fresh graduate and have just got my first job as a programmer in Hong Kong. As the topic described, I need to use C# to control the ports on the Cisco switch.

    I have search and study for quite a long time so I have the basic knowledge about SNMP and MIB. I can find some articles talking about how to manage a cisco switch but none of them specified how do I enable and disable ports. At this moment I think I need to config the switch so that it enable the SNMP service, then I should send a SNMP Set packet to turn on/off the particular port. Is it correct?

    Anyone have some experience on it and like to share with me? Please leave some suggestion. And if you have read some useful websites before, please kindly leave the url here so I can have a look too.

    Thank you so much for your attention.