aacable79

C# ibbi Switcher - Cisco Manager

Apr 26th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.23 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net.Sockets;
  10. using SnmpSharpNet;
  11. using System.Threading.Tasks;
  12.  
  13. namespace WindowsFormsApplication2
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public class Globals
  18.         {
  19.             public static string P1 = "";
  20.             public static string P2 = "";
  21.             public static string P3 = "";
  22.             public static string P4 = "";
  23.             public static string P5 = "";
  24.             public static string P6 = "";
  25.             public static string P7 = "";
  26.             public static string P8 = "";
  27.             public static string P9 = "";
  28.             public static string P10 = "";
  29.             public static string P11 = "";
  30.             public static string P12 = "";
  31.             public static string P13 = "";
  32.             public static string P14 = "";
  33.             public static string P15 = "";
  34.             public static string P16 = "";
  35.             public static string P17 = "";
  36.             public static string P18 = "";
  37.             public static string P19 = "";
  38.             public static string P20 = "";
  39.             public static string P21 = "";
  40.             public static string P22 = "";
  41.             public static string P23 = "";
  42.             public static string P24 = "";
  43.             public static string PL1 = "";
  44.             public static string PL2 = "";
  45.             public static string PL3 = "";
  46.             public static string PL4 = "";
  47.             public static string PL5 = "";
  48.             public static string PL6 = "";
  49.             public static string PL7 = "";
  50.             public static string PL8 = "";
  51.             public static string PL9 = "";
  52.             public static string PL10 = "";
  53.             public static string PL11 = "";
  54.             public static string PL12 = "";
  55.             public static string PL13 = "";
  56.             public static string PL14 = "";
  57.             public static string PL15 = "";
  58.             public static string PL16 = "";
  59.             public static string PL17 = "";
  60.             public static string PL18 = "";
  61.             public static string PL19 = "";
  62.             public static string PL20 = "";
  63.             public static string PL21 = "";
  64.             public static string PL22 = "";
  65.             public static string PL23 = "";
  66.             public static string PL24 = "";
  67.  
  68.         }
  69.  
  70.         public Form1()
  71.         {
  72.             InitializeComponent();
  73.             timer1.Stop();
  74.             timer1.Enabled = false;
  75.         }
  76.  
  77.         private void Form1_Load(object sender, EventArgs e)
  78.         {
  79.             portReset();
  80.             datelabel.Text = DateTime.Now.ToLongDateString();
  81.             timelabel.Text = DateTime.Now.ToLongTimeString();
  82.         }
  83.  
  84.  
  85.         private void portReset()
  86.         {
  87.             port1.Image = Properties.Resources.port_nostatus;
  88.             port2.Image = Properties.Resources.port_nostatus;
  89.             port3.Image = Properties.Resources.port_nostatus;
  90.             port4.Image = Properties.Resources.port_nostatus;
  91.             port5.Image = Properties.Resources.port_nostatus;
  92.             port6.Image = Properties.Resources.port_nostatus;
  93.             port7.Image = Properties.Resources.port_nostatus;
  94.             port8.Image = Properties.Resources.port_nostatus;
  95.             port9.Image = Properties.Resources.port_nostatus;
  96.             port10.Image = Properties.Resources.port_nostatus;
  97.             port11.Image = Properties.Resources.port_nostatus;
  98.             port12.Image = Properties.Resources.port_nostatus;
  99.             port13.Image = Properties.Resources.port_nostatus;
  100.             port14.Image = Properties.Resources.port_nostatus;
  101.             port15.Image = Properties.Resources.port_nostatus;
  102.             port16.Image = Properties.Resources.port_nostatus;
  103.             port17.Image = Properties.Resources.port_nostatus;
  104.             port18.Image = Properties.Resources.port_nostatus;
  105.             port19.Image = Properties.Resources.port_nostatus;
  106.             port20.Image = Properties.Resources.port_nostatus;
  107.             port21.Image = Properties.Resources.port_nostatus;
  108.             port22.Image = Properties.Resources.port_nostatus;
  109.             port23.Image = Properties.Resources.port_nostatus;
  110.             port24.Image = Properties.Resources.port_nostatus;
  111.             p1textBox1.Text = null;
  112.             p2textBox1.Text = null;
  113.             p3textBox1.Text = null;
  114.             p4textBox1.Text = null;
  115.             p5textBox1.Text = null;
  116.             p6textBox1.Text = null;
  117.             p7textBox1.Text = null;
  118.             p8textBox1.Text = null;
  119.             p9textBox1.Text = null;
  120.             p10textBox1.Text = null;
  121.             p11textBox1.Text = null;
  122.             p12textBox1.Text = null;
  123.             p13textBox1.Text = null;
  124.             p14textBox1.Text = null;
  125.             p15textBox1.Text = null;
  126.             p16textBox1.Text = null;
  127.             p17textBox1.Text = null;
  128.             p18textBox1.Text = null;
  129.             p19textBox1.Text = null;
  130.             p20textBox1.Text = null;
  131.             p21textBox1.Text = null;
  132.             p22textBox1.Text = null;
  133.             p23textBox1.Text = null;
  134.             p24textBox1.Text = null;
  135.         }
  136.  
  137.         private async void snmpGetFunc()
  138.         {
  139.             timer1.Enabled = true;
  140.  
  141.             this.Invoke((MethodInvoker)delegate
  142.             {
  143.                 lastUpdateLabel.Text = "Last Updated @" + DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString();
  144.             });
  145.             OctetString community = new OctetString("PUBLIC");
  146.             AgentParameters param = new AgentParameters(community);
  147.             param.Version = SnmpVersion.Ver2;
  148.             IpAddress agent = new IpAddress("10.0.0.1");
  149.             UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
  150.             Pdu pdu = new Pdu(PduType.Get);
  151.             // Ports  
  152.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10101");
  153.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10102");
  154.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10103");
  155.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10104");
  156.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10105");
  157.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10106");
  158.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10107");
  159.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10108");
  160.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10109");
  161.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10110");
  162.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10111");
  163.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10112");
  164.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10113");
  165.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10114");
  166.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10115");
  167.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10116");
  168.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10117");
  169.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10118");
  170.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10119");
  171.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10120");
  172.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10121");
  173.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10122");
  174.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10123");
  175.             pdu.VbList.Add("1.3.6.1.2.1.2.2.1.8.10605");
  176.             // Ports End
  177.             // Now quering switch related data
  178.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10101");
  179.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10102");
  180.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10103");
  181.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10104");
  182.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10105");
  183.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10106");
  184.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10107");
  185.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10108");
  186.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10109");
  187.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10110");
  188.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10111");
  189.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10112");
  190.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10113");
  191.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10114");
  192.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10115");
  193.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10116");
  194.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10117");
  195.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10118");
  196.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10119");
  197.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10120");
  198.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10121");
  199.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10122");
  200.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10123");
  201.             pdu.VbList.Add("1.3.6.1.2.1.31.1.1.1.18.10605");
  202.             // Make SNMP request
  203.             try
  204.             {
  205.                 SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);
  206.             }
  207.  
  208.             catch (SnmpException ex)
  209.             {
  210.                 this.Invoke((MethodInvoker)delegate
  211.                 {
  212.                     this.StatusTextBox1.AppendText("\r\n" + ex.Message + "Either Device or SNMP not responding. Retrying again ...");
  213.                 });
  214.                 return;
  215.             }
  216.  
  217.             if (timer1.Enabled == true)
  218.             {
  219.                 SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);
  220.                 Globals.P1 = result.Pdu.VbList[0].Value.ToString();
  221.                 Globals.P2 = result.Pdu.VbList[1].Value.ToString();
  222.                 Globals.P3 = result.Pdu.VbList[2].Value.ToString();
  223.                 Globals.P4 = result.Pdu.VbList[3].Value.ToString();
  224.                 Globals.P5 = result.Pdu.VbList[4].Value.ToString();
  225.                 Globals.P6 = result.Pdu.VbList[5].Value.ToString();
  226.                 Globals.P7 = result.Pdu.VbList[6].Value.ToString();
  227.                 Globals.P8 = result.Pdu.VbList[7].Value.ToString();
  228.                 Globals.P9 = result.Pdu.VbList[8].Value.ToString();
  229.                 Globals.P10 = result.Pdu.VbList[9].Value.ToString();
  230.                 Globals.P11 = result.Pdu.VbList[10].Value.ToString();
  231.                 Globals.P12 = result.Pdu.VbList[11].Value.ToString();
  232.                 Globals.P13 = result.Pdu.VbList[12].Value.ToString();
  233.                 Globals.P14 = result.Pdu.VbList[13].Value.ToString();
  234.                 Globals.P15 = result.Pdu.VbList[14].Value.ToString();
  235.                 Globals.P16 = result.Pdu.VbList[15].Value.ToString();
  236.                 Globals.P17 = result.Pdu.VbList[16].Value.ToString();
  237.                 Globals.P18 = result.Pdu.VbList[17].Value.ToString();
  238.                 Globals.P19 = result.Pdu.VbList[18].Value.ToString();
  239.                 Globals.P20 = result.Pdu.VbList[19].Value.ToString();
  240.                 Globals.P21 = result.Pdu.VbList[20].Value.ToString();
  241.                 Globals.P22 = result.Pdu.VbList[21].Value.ToString();
  242.                 Globals.P23 = result.Pdu.VbList[22].Value.ToString();
  243.                 Globals.P24 = result.Pdu.VbList[23].Value.ToString();
  244.                 Globals.PL1 = result.Pdu.VbList[24].Value.ToString();
  245.                 Globals.PL2 = result.Pdu.VbList[25].Value.ToString();
  246.                 Globals.PL3 = result.Pdu.VbList[26].Value.ToString();
  247.                 Globals.PL4 = result.Pdu.VbList[27].Value.ToString();
  248.                 Globals.PL5 = result.Pdu.VbList[28].Value.ToString();
  249.                 Globals.PL6 = result.Pdu.VbList[29].Value.ToString();
  250.                 Globals.PL7 = result.Pdu.VbList[30].Value.ToString();
  251.                 Globals.PL8 = result.Pdu.VbList[31].Value.ToString();
  252.                 Globals.PL9 = result.Pdu.VbList[32].Value.ToString();
  253.                 Globals.PL10 = result.Pdu.VbList[33].Value.ToString();
  254.                 Globals.PL11 = result.Pdu.VbList[34].Value.ToString();
  255.                 Globals.PL12 = result.Pdu.VbList[35].Value.ToString();
  256.                 Globals.PL13 = result.Pdu.VbList[36].Value.ToString();
  257.                 Globals.PL14 = result.Pdu.VbList[37].Value.ToString();
  258.                 Globals.PL15 = result.Pdu.VbList[38].Value.ToString();
  259.                 Globals.PL16 = result.Pdu.VbList[39].Value.ToString();
  260.                 Globals.PL17 = result.Pdu.VbList[40].Value.ToString();
  261.                 Globals.PL18 = result.Pdu.VbList[41].Value.ToString();
  262.                 Globals.PL19 = result.Pdu.VbList[42].Value.ToString();
  263.                 Globals.PL20 = result.Pdu.VbList[43].Value.ToString();
  264.                 Globals.PL21 = result.Pdu.VbList[44].Value.ToString();
  265.                 Globals.PL22 = result.Pdu.VbList[45].Value.ToString();
  266.                 Globals.PL23 = result.Pdu.VbList[46].Value.ToString();
  267.                 Globals.PL24 = result.Pdu.VbList[47].Value.ToString();
  268.                 this.Invoke((MethodInvoker)delegate
  269.                 {
  270.                     //textBox1.BackColor = Color.Gray;
  271.                     plabel1.Text = Globals.PL1;
  272.                     plabel2.Text = Globals.PL2;
  273.                     plabel3.Text = Globals.PL3;
  274.                     plabel4.Text = Globals.PL4;
  275.                     plabel5.Text = Globals.PL5;
  276.                     plabel6.Text = Globals.PL6;
  277.                     plabel7.Text = Globals.PL7;
  278.                     plabel8.Text = Globals.PL8;
  279.                     plabel9.Text = Globals.PL9;
  280.                     plabel10.Text = Globals.PL10;
  281.                     plabel11.Text = Globals.PL11;
  282.                     plabel12.Text = Globals.PL12;
  283.                     plabel13.Text = Globals.PL13;
  284.                     plabel14.Text = Globals.PL14;
  285.                     plabel15.Text = Globals.PL15;
  286.                     plabel16.Text = Globals.PL16;
  287.                     plabel17.Text = Globals.PL17;
  288.                     plabel18.Text = Globals.PL18;
  289.                     plabel19.Text = Globals.PL19;
  290.                     plabel20.Text = Globals.PL20;
  291.                     plabel21.Text = Globals.PL21;
  292.                     plabel22.Text = Globals.PL22;
  293.                     plabel23.Text = Globals.PL23;
  294.                     plabel24.Text = Globals.PL24;
  295.                     //});
  296.                     if (Globals.P1 == "1")
  297.                     {
  298.                         port1.Image = Properties.Resources.port_up;
  299.                         p1textBox1.Text = Globals.P1;
  300.                     }
  301.                     else
  302.                     {
  303.                         port1.Image = Properties.Resources.port_down;
  304.                     }
  305.  
  306.                     if (Globals.P2 == "1")
  307.                     {
  308.                         port2.Image = Properties.Resources.port_up;
  309.                         p2textBox1.Text = Globals.P2;
  310.                     }
  311.                     else
  312.                     {
  313.                         port2.Image = Properties.Resources.port_down;
  314.                     }
  315.  
  316.                     if (Globals.P3 == "1")
  317.                     {
  318.                         port3.Image = Properties.Resources.port_up;
  319.                         p3textBox1.Text = Globals.P3;
  320.                     }
  321.                     else
  322.                     {
  323.                         port3.Image = Properties.Resources.port_down;
  324.                     }
  325.  
  326.                     if (Globals.P4 == "1")
  327.                     {
  328.                         port4.Image = Properties.Resources.port_up;
  329.                         p4textBox1.Text = Globals.P4;
  330.                     }
  331.                     else
  332.                     {
  333.                         port4.Image = Properties.Resources.port_down;
  334.                     }
  335.  
  336.                     if (Globals.P5 == "1")
  337.                     {
  338.                         port5.Image = Properties.Resources.port_up;
  339.                         p5textBox1.Text = Globals.P5;
  340.                     }
  341.                     else
  342.                     {
  343.                         port5.Image = Properties.Resources.port_down;
  344.                         //this.StatusTextBox1.Text += string.Format("Port 5 is now Down!\r\n");
  345.                     }
  346.  
  347.                     if (Globals.P6 == "1")
  348.                     {
  349.                         port6.Image = Properties.Resources.port_up;
  350.                         p6textBox1.Text = Globals.P6;
  351.                     }
  352.                     else
  353.                     {
  354.                         port6.Image = Properties.Resources.port_down;
  355.                     }
  356.  
  357.                     if (Globals.P7 == "1")
  358.                     {
  359.                         port7.Image = Properties.Resources.port_up;
  360.                     }
  361.                     else
  362.                     {
  363.                         port7.Image = Properties.Resources.port_down;
  364.                     }
  365.  
  366.                     if (Globals.P8 == "1")
  367.                     {
  368.                         port8.Image = Properties.Resources.port_up;
  369.                     }
  370.                     else
  371.                     {
  372.                         port8.Image = Properties.Resources.port_down;
  373.                     }
  374.  
  375.                     if (Globals.P9 == "1")
  376.                     {
  377.                         port9.Image = Properties.Resources.port_up;
  378.                     }
  379.                     else
  380.                     {
  381.                         port9.Image = Properties.Resources.port_down;
  382.                     }
  383.                     if (Globals.P10 == "1")
  384.                     {
  385.                         port10.Image = Properties.Resources.port_up;
  386.                     }
  387.                     else
  388.                     {
  389.                         port10.Image = Properties.Resources.port_down;
  390.                     }
  391.  
  392.                     if (Globals.P11 == "1")
  393.                     {
  394.                         port11.Image = Properties.Resources.port_up;
  395.                     }
  396.                     else
  397.                     {
  398.                         port11.Image = Properties.Resources.port_down;
  399.                     }
  400.  
  401.                     if (Globals.P12 == "1")
  402.                     {
  403.                         port12.Image = Properties.Resources.port_up;
  404.                     }
  405.                     else
  406.                     {
  407.                         port12.Image = Properties.Resources.port_down;
  408.                     }
  409.  
  410.                     if (Globals.P13 == "1")
  411.                     {
  412.                         port13.Image = Properties.Resources.port_up;
  413.                     }
  414.                     else
  415.                     {
  416.                         port13.Image = Properties.Resources.port_down;
  417.                     }
  418.  
  419.                     if (Globals.P14 == "1")
  420.                     {
  421.                         port14.Image = Properties.Resources.port_up;
  422.                     }
  423.                     else
  424.                     {
  425.                         port14.Image = Properties.Resources.port_down;
  426.                     }
  427.  
  428.  
  429.                     if (Globals.P15 == "1")
  430.                     {
  431.                         port15.Image = Properties.Resources.port_up;
  432.                     }
  433.                     else
  434.                     {
  435.                         port15.Image = Properties.Resources.port_down;
  436.                     }
  437.  
  438.                     if (Globals.P16 == "1")
  439.                     {
  440.                         port16.Image = Properties.Resources.port_up;
  441.                     }
  442.                     else
  443.                     {
  444.                         port16.Image = Properties.Resources.port_down;
  445.                     }
  446.  
  447.  
  448.  
  449.                     if (Globals.P17 == "1")
  450.                     {
  451.                         port17.Image = Properties.Resources.port_up;
  452.                     }
  453.                     else
  454.                     {
  455.                         port17.Image = Properties.Resources.port_down;
  456.                     }
  457.  
  458.  
  459.                     if (Globals.P18 == "1")
  460.                     {
  461.                         port18.Image = Properties.Resources.port_up;
  462.                     }
  463.                     else
  464.                     {
  465.                         port18.Image = Properties.Resources.port_down;
  466.                     }
  467.  
  468.                     if (Globals.P19 == "1")
  469.                     {
  470.                         port19.Image = Properties.Resources.port_up;
  471.                     }
  472.                     else
  473.                     {
  474.                         port19.Image = Properties.Resources.port_down;
  475.                     }
  476.  
  477.                     if (Globals.P20 == "1")
  478.                     {
  479.                         port20.Image = Properties.Resources.port_up;
  480.                     }
  481.                     else
  482.                     {
  483.                         port20.Image = Properties.Resources.port_down;
  484.                     }
  485.  
  486.                     if (Globals.P21 == "1")
  487.                     {
  488.                         port21.Image = Properties.Resources.port_up;
  489.                     }
  490.                     else
  491.                     {
  492.                         port21.Image = Properties.Resources.port_down;
  493.                     }
  494.  
  495.                     if (Globals.P22 == "1")
  496.                     {
  497.                         port22.Image = Properties.Resources.port_up;
  498.                     }
  499.                     else
  500.                     {
  501.                         port22.Image = Properties.Resources.port_down;
  502.                     }
  503.  
  504.                     if (Globals.P23 == "1")
  505.                     {
  506.                         port23.Image = Properties.Resources.port_up;
  507.                     }
  508.                     else
  509.                     {
  510.                         port23.Image = Properties.Resources.port_down;
  511.                     }
  512.  
  513.                     if (Globals.P24 == "1")
  514.                     {
  515.                         port24.Image = Properties.Resources.port_up;
  516.                         p24textBox1.Text = Globals.P24;
  517.                     }
  518.                     else
  519.                     {
  520.                         port24.Image = Properties.Resources.port_down;
  521.                         p24textBox1.Text = Globals.P24;
  522.                     }
  523.                 });
  524.             }
  525.         }
  526.  
  527.  
  528.  
  529.  
  530.  
  531.         private async void button1_Click(object sender, EventArgs e)
  532.         {
  533.             if (timer1.Enabled == true)
  534.             {
  535.                 this.StatusTextBox1.Text += string.Format("Monitoring already started. Stop it to first to start new instance !\r\n");
  536.             }
  537.             else
  538.             {
  539.                 timer1.Enabled = true;
  540.                 this.statusLoadinBar.Image = Properties.Resources.loading_gif;
  541.                 await Task.Run(() =>
  542.                 {
  543.                     snmpGetFunc();
  544.                 });
  545.                 StatusTextBox1.Text = String.Empty;
  546.                 this.StatusTextBox1.Text += string.Format("Starting monitoring of Cisco Switch Ports. \r\n");
  547.             }
  548.         }
  549.  
  550.  
  551.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  552.         {
  553.             Application.Exit();
  554.         }
  555.  
  556.  
  557.         private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
  558.         {
  559.             Application.Exit();
  560.         }
  561.  
  562.         private void pictureBox1_Click(object sender, EventArgs e)
  563.         {
  564.             Application.Exit();
  565.         }
  566.  
  567.         private void timer4dt_Tick(object sender, EventArgs e)
  568.         {
  569.             timelabel.Text = DateTime.Now.ToLongTimeString();
  570.             timer4dt.Start();
  571.         }
  572.         private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  573.         {
  574.         }
  575.  
  576.         private void stopButton_Click(object sender, EventArgs e)
  577.         {
  578.             if (timer1.Enabled == true)
  579.             {
  580.                 timer1.Enabled = false;
  581.                 timer1.Stop();
  582.                 portReset();
  583.                 this.statusLoadinBar.Image = null;
  584.                 this.StatusTextBox1.AppendText("\r\nMonitoring of switch have been Stopped on user request \r\n");
  585.             }
  586.             else
  587.             {
  588.                 this.StatusTextBox1.AppendText("\r\nMonitoring not started yet !\r\n");
  589.             }
  590.         }
  591.  
  592.         private void timer1_Tick(object sender, EventArgs e)
  593.         {
  594.             snmpGetFunc();
  595.         }
  596.         private void exitButton_Click(object sender, EventArgs e)
  597.         {
  598.             this.statusLoadinBar.Image = null;
  599.             timer1.Stop();
  600.             portReset();
  601.             this.StatusTextBox1.AppendText("\r\nExiting on user request \r\n");
  602.  
  603.             Application.Exit();
  604.         }
  605.         private void StatusTextBox1_TextChanged(object sender, EventArgs e)
  606.         {
  607.             StatusTextBox1.SelectionStart = StatusTextBox1.Text.Length;
  608.             StatusTextBox1.ScrollToCaret();
  609.         }
  610.         private void p1textBox1_TextChanged(object sender, EventArgs e)
  611.         {
  612.             if (Globals.P1 == "1")
  613.                 this.StatusTextBox1.AppendText("\r\nPort 1 is now UP @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  614.             else
  615.                 this.StatusTextBox1.AppendText("\r\nPort 1 is now DOWN! @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  616.         }
  617.         private void p5textBox1_TextChanged_1(object sender, EventArgs e)
  618.         {
  619.             if (Globals.P5 == "1")
  620.                 this.StatusTextBox1.AppendText("\r\nPort 5 is now UP @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  621.             else
  622.                 this.StatusTextBox1.AppendText("\r\nPort 5 is now DOWN! @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  623.         }
  624.         private void p24textBox1_TextChanged(object sender, EventArgs e)
  625.         {
  626.             if (Globals.P24 == "1")
  627.                 this.StatusTextBox1.AppendText("\r\nPort 24 is now UP @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  628.             else
  629.                 this.StatusTextBox1.AppendText("\r\nPort 24 is now DOWN! @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  630.         }
  631.         private void p2textBox1_TextChanged(object sender, EventArgs e)
  632.         {
  633.             if (Globals.P2 == "1")
  634.                 this.StatusTextBox1.AppendText("\r\nPort 2 is now UP @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  635.             else
  636.                 this.StatusTextBox1.AppendText("\r\nPort 2 is now DOWN! @" + DateTime.Now.ToLongDateString() + " / " + DateTime.Now.ToLongTimeString());
  637.         }
  638.     }
  639. }
Add Comment
Please, Sign In to add comment