How to enable or disable ports in a Cisco Catalyst 2960 using C #?

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

I have been searching and studying for quite some time, so I have basic knowledge of SNMP and MIB. I can find some articles on how to manage a cisco switch, but none of them indicated how to enable or disable ports. At this point, it seems to me that I need to configure the switch to enable the SNMP service, then I have to send the SNMP Set packet to enable / disable a specific port. Is it correct?

Does anyone have experience and enjoy sharing with me? Please leave some suggestion. And if you have read some useful sites before, please kindly leave a URL here so that I can also see.

Thank you so much for your attention.

+5
source share
3 answers

I know three methods (I like the first most):

Option 1:
A common way to approach something like this is to use automatic telnet (or automatic ssh) to send the appropriate commands. IOS is pretty standardized for the most part and works great in that direction.

The TCL Expect package is ideal for this kind of thing ... I assume there is a C # implementation.

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

2:
, , , :
IF-MIB:: ifAdminStatus SNMP ( NET-SNMP):

UP:
snmpset -v1 -c IF-MIB:: ifAdminStatus.interface 1

DOWN:
snmpset -v1 -c IF-MIB:: ifAdminStatus.interface 2

( "" - , , MIB - 1.3.6.1.2.1.2.2.1.2, .)

( , , # snmpset, ... SNMP .)

3:
SNMP TFTP-.
:
1.
2.
3.
4. ( , )

+7

POE (cisco zyxel), snmp POE

SNMPv2-SMI:: -2.105.1.1.1.3.1.x x ( 8- 1 ~ 8 24- 1 ~ 24)

IF-MIB:: ifAdminStatus.interface /, - reset / / /VoIP- .

POE

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

POE

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

3,

+1

telnet Google MinimalisticTelnet

SNMP, : : snmp SnmpSharpNet

using SnmpSharpNet;

1 6:

Console.WriteLine("Ports Disabler ");
            UdpTarget target = new UdpTarget((IPAddress)new IpAddress("192.168.1.200"));
            Pdu pdu = new Pdu(PduType.Set);
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.1"), new Integer32(2));
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.2"), new Integer32(2));
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.3"), new Integer32(2));
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.4"), new Integer32(2));
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.5"), new Integer32(2));
            pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.6"), new Integer32(2));
            AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString("2645"));
            SnmpV2Packet response;
            try
            {
                // Send request and wait for response
                response = target.Request(pdu, aparam) as SnmpV2Packet;
            }
            catch (Exception ex)
            {
                // If exception happens, it will be returned here
                Console.WriteLine(String.Format("Request failed with exception: {0}", ex.Message));
                target.Close();
                return;
            }
            // Make sure we received a response
            if (response == null)
            {
                Console.WriteLine("Error in sending SNMP request.");
            }
            else
            {
                // Check if we received an SNMP error from the agent
                if (response.Pdu.ErrorStatus != 0)
                {
                    Console.WriteLine(String.Format("SNMP agent returned ErrorStatus {0} on index {1}",
                      response.Pdu.ErrorStatus, response.Pdu.ErrorIndex) + response.ToString());
                }
                else
                {
                    // Everything is ok. Agent will return the new value for the OID we changed
                    Console.WriteLine(String.Format("Agent response {0}: {1}",
                      response.Pdu[0].Oid.ToString(), response.Pdu[0].Value.ToString()));
                }
            }

, ,

0
source

All Articles