Beispiel #1
0
        public void ParseMibFiles()
        {
            if (MIBFilePath == null)
            {
                throw new Exception("Path to mib files cant be null!!!");
            }
            var mibDirectory = new DirectoryInfo(MIBFilePath);

            FileInfo[] lstFileName = mibDirectory.GetFiles("*.*");
            var        dasf        = new StringBuilder();

            foreach (FileInfo fileName in lstFileName)
            {
                using (var flSteam = new FileStream(MIBFilePath + Path.DirectorySeparatorChar + fileName.Name, FileMode.Open))
                {
                    var mss = new byte[flSteam.Length];
                    flSteam.Read(mss, 0, (int)flSteam.Length);
                    flSteam.Close();
                    StringBuilder SearchName = new StringBuilder((new UTF8Encoding()).GetString(mss)); //"";

                    Match matchSNMP;
                    //@"([a-zA-Z0-9._%+-]+[ ]+)(OBJECT-TYPE|OBJECT IDENTIFIER|OBJECT-IDENTITY|MODULE-IDENTITY|OBJECT-GROUP|MODULE-COMPLIANCE|NOTIFICATION-TYPE|NOTIFICATION-GROUP)([ ]|[ ]+|[^.*$]+)::=.*?}",
                    Regex regSNMP =
                        new Regex(
                            @"((^[a-zA-Z0-9-]+).*)(OBJECT-TYPE|OBJECT IDENTIFIER|OBJECT-IDENTITY|MODULE-IDENTITY|OBJECT-GROUP|MODULE-COMPLIANCE|NOTIFICATION-TYPE|NOTIFICATION-GROUP)((.*[\n\r])*?)(.*::=.*?[.\r\n ]*?.*})",
                            RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    //    @"((^[a-zA-Z0-9-]+).*)(OBJECT-TYPE|OBJECT IDENTIFIER|OBJECT-IDENTITY|MODULE-IDENTITY|OBJECT-GROUP|MODULE-COMPLIANCE|NOTIFICATION-TYPE|NOTIFICATION-GROUP)([.\n\r]*?)(.*::=[\r\n ]*?.*})",


                    for (matchSNMP = regSNMP.Match(SearchName.ToString()); matchSNMP.Success; matchSNMP = matchSNMP.NextMatch())
                    {
                        ParseMib(matchSNMP.ToString());
                    }
                    flSteam.Close();
                }
            }
            MIB test = new MIB();

            test.Name   = "noAuthNoPriv";
            test.OID    = 1;
            test.Parent = null;
            MibList.Add(test);
        }
Beispiel #2
0
        private string FindMIB(List <string> Value, string parent)
        {
            if (MibList.Count() == 0)
            {
                ParseMibFiles();
            }
            int Val;

            Val = Convert.ToInt32(Value[0]);
            if (parent == null)
            {
                parent = "iso";
                Value.RemoveAt(0);
                return(FindMIB(Value, parent));
            }
            else
            {
                IEnumerable <MIB> Mas = from c in MibList
                                        where c.OID == Val && c.Parent == parent
                                        select c;
                if (Mas.Count() > 0)
                {
                    MIB Nasao = Mas.First();
                    Value.RemoveAt(0);
                    if (Value.Count() >= 1)
                    {
                        return(FindMIB(Value, Nasao.Name));
                    }
                    else
                    {
                        return(Nasao.Name);
                    }
                }
            }
            string Result = "";

            foreach (string a in Value)
            {
                Result += "." + a;
            }
            return(parent + Result); // throw new Exception("No Find Exec");
        }
Beispiel #3
0
        private string FindOID(string Value)
        {
            if (MibList.Count() == 0)
            {
                ParseMibFiles();
            }
            if (Value == "iso")
            {
                return("1");
            }
            IEnumerable <MIB> Mas = from c in MibList
                                    where c.Name == Value
                                    select c;

            if (Mas.Count() > 0)
            {
                MIB Nasao = Mas.First();
                return(FindOID(Nasao.Parent) + "." + Nasao.OID);
            }
            else
            {
                return("." + Value); // throw new Exception("No Find Exec");
            }
        }