Exemplo n.º 1
0
        public SnmpUseInform(string s)
        {
            string[] temp   = s.Split(new char[] { ':' });
            string   toNext = "";
            Int32    i      = 0;

            if (temp.Length < 2)
            {
                return;
            }
            this.oid   = temp[0];
            this.value = temp[1];
            if (temp.Length < 4)
            {
                this.next = null;
            }
            else
            {
                for (i = 2; i < temp.Length; i++)
                {
                    toNext += temp[i] + ":";
                }
                this.next = new SnmpUseInform(toNext);
            }
        }
Exemplo n.º 2
0
        public SnmpTrapSession(string all)
        {
            //string[] temp = all.Split(new char[] {':'});
            //this.version = temp[0];
            //this.address = temp[1];
            //this.port = Convert.ToInt16(temp[2]);
            //this.oid = temp[3];
            //if(temp.Length >= 5)
            //    this.timeTick = Convert.ToInt32(temp[4]);
            //this.AllofThem = all;

            string[] part = all.Split(new char[] { ';' });
            if (part.Length != 2)
            {
                return;
            }
            string[] part1 = part[0].Split(new char[] { ':' });
            if (part1.Length < 3)
            {
                return;
            }
            this.version = part1[0];
            //this.address = part1[1];
            //this.port = Convert.ToInt16(part1[2]);
            string[] part2 = part1[1].Split(new char[] { '/' });
            this.address = part2[0];
            this.port    = Convert.ToInt32(part2[1]);
            this.oid     = part1[2];
            this.head    = new SnmpUseInform(part[1]);
            AllofThem    = all;
        }
Exemplo n.º 3
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;
                    }
                }
            }
        }