Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            #region create a thread to listen for trap

            SnmpTrapListen trapListener = new SnmpTrapListen(10162);
            trapListener.sendPortToCallback(10162);
            Thread snmpTrapListener1 = new Thread(new ParameterizedThreadStart(trapListener.sendPortToCallback));
            snmpTrapListener1.IsBackground = true;
            snmpTrapListener1.Start(trapListener.portToListen);

            #endregion
            Application.Run(new FormForFirst());
        }
Beispiel #2
0
        //public long trapCnt = 0;
        //public long trapCntPre = 0;
        private void timerForUpdate_Tick(object sender, EventArgs e)
        {
            long trapCnt = 0;

            trapCnt = SnmpTrapListen.getTrapCounter();
            if (trapCnt > 0)
            {
                StringBuilder UpdateInformation = new StringBuilder();
                IntPtr        ptr;
                ptr = SnmpTrapListen.getTrapInformation();
                string temp = Marshal.PtrToStringAnsi(ptr);
                //textBoxForTrap.Text += temp;
                //trapCntPre = trapCnt;
                string[] part = temp.Split(new char[] { '\n' });
                //if (part.Length != trapCnt)
                //{
                //    return;
                //}
                long i = 0;
                for (i = 0; i < part.Length - 1; i++)
                {
                    SnmpTrapSession newsession = new SnmpTrapSession(part[i]);
                    TreeNode        t          = treeViewForTrap.Nodes.Add(newsession.address + "  " + System.DateTime.Now.ToString());
                    t.Nodes.Add("version:" + newsession.version);
                    t.Nodes.Add("ip adress:" + newsession.address);
                    t.Nodes.Add("port:" + newsession.port);
                    t.Nodes.Add("trap oid:" + newsession.oid);
                    SnmpUseInform s = newsession.head;
                    while (s != null)
                    {
                        t.Nodes.Add("Context oid:" + s.oid);
                        t.Nodes.Add("Context value:" + s.value);
                        s = s.next;
                    }
                }
            }
        }