Exemplo n.º 1
0
        public void TestToString()
        {
            var transmission = new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 2, 1, 10 });

            Assert.AreEqual(".iso.org.dod.internet.mgmt.mib-2.transmission",
                            transmission.ToString(DefaultObjectRegistry.Instance));
            Assert.AreEqual(".1.3.6.1.2.1.10", transmission.ToString(null));
        }
Exemplo n.º 2
0
        //private readonly Map<PropertyIdentifier, Encodable> properties = new HashMap<PropertyIdentifier, Encodable>();
        //private readonly List<ObjectCovSubscription> covSubscriptions = new ArrayList<ObjectCovSubscription>();

        public BACnetObject(LocalDevice localDevice, ObjectIdentifier id)
        {
            this.localDevice = localDevice;
            if (id == null)
            {
                throw new ArgumentException("object id cannot be null");
            }
            Id = id;

            try
            {
                setProperty(PropertyIdentifier.ObjectName, new CharacterString(id.ToString()));

                // Set any default values.
                IList defs = ObjectProperties.getPropertyTypeDefinitions(id.ObjectType);
                foreach (PropertyTypeDefinition def in defs)
                {
                    if (def.DefaultValue != null)
                    {
                        setProperty(def.PropertyIdentifier, def.DefaultValue);
                    }
                }
            }
            catch (BACnetServiceException e)
            {
                // Should never happen, but wrap in an unchecked just in case.
                throw new BACnetRuntimeException(e);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns interface descriptions, indexed by IfIndex.
        /// </summary>
        /// <returns></returns>
        public Dictionary <int, string> GetInterfaceDescriptions()
        {
            // OID Value
            ObjectIdentifier oidRequested = new ObjectIdentifier(".1.3.6.1.2.1.31.1.1");
            string           szBaseOid    = oidRequested.ToString() + ".1.";

            // Where our SNMP data will go.
            Dictionary <string, ISnmpData> snmpResult = new Dictionary <string, ISnmpData>();
            Dictionary <int, string>       dictResult = new Dictionary <int, string>();

            try
            {
                snmpResult = this.GetOidWalk(oidRequested);
            }
            catch {}

            //
            // Determine the number of rows.
            // Get a list of all the interfaces
            ArrayList dRowArray  = new ArrayList();
            int       dRowsAdded = 0;

            foreach (string s in snmpResult.Keys)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid    = s.Split('.');
                int      dDataTypeId = Convert.ToInt32(szRowOid[10]);
                string   szRowIdPart = szRowOid[11];

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Contains(szRowIdPart))
                {
                    dRowArray.Add(szRowIdPart);
                    dRowsAdded++;
                }
            }

            // Now we have the row parts, get the values.
            int rowCurrent = 0;
            int dRowCount  = dRowArray.Count;

            while (rowCurrent < dRowCount)
            {
                string szDescription   = string.Empty;
                string szRowCurrentOid = dRowArray[rowCurrent].ToString();
                int    ifIndex         = Convert.ToInt32(szRowCurrentOid);
                if (snmpResult.Keys.Contains(szBaseOid + 18 + "." + szRowCurrentOid))
                {
                    szDescription = snmpResult[szBaseOid + 18 + "." + szRowCurrentOid].ToString();
                }

                dictResult.Add(ifIndex, szDescription);
                rowCurrent++;
            }

            return(dictResult);
        }
Exemplo n.º 4
0
 static Statement ExecuteStatementMultiple(ObjectIdentifier id, Func <Expression, Statement[]> objectTransform)
 {
     return(new CallStaticMethod(
                TryExecuteOnObjectsWithTag,
                new StringLiteral(id.ToString()),
                new Lambda(
                    Signature.Action(Variable.This),
                    Enumerable.Empty <BindVariable>(),
                    objectTransform(new ReadVariable(Variable.This)))));
 }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void parse(byte[] encoded) throws java.io.IOException
        private void Parse(sbyte[] encoded)
        {
            DerInputStream attributeValue = new DerInputStream(encoded);

            DerValue[]       attrSeq     = attributeValue.getSequence(2);
            ObjectIdentifier type        = attrSeq[0].OID;
            DerInputStream   attrContent = new DerInputStream(attrSeq[1].toByteArray());

            DerValue[] attrValueSet = attrContent.getSet(1);
            String[]   values       = new String[attrValueSet.Length];
            String     printableString;

            for (int i = 0; i < attrValueSet.Length; i++)
            {
                if (attrValueSet[i].tag == DerValue.tag_OctetString)
                {
                    values[i] = Debug.ToString(attrValueSet[i].OctetString);
                }
                else if ((printableString = attrValueSet[i].AsString) != null)
                {
                    values[i] = printableString;
                }
                else if (attrValueSet[i].tag == DerValue.tag_ObjectId)
                {
                    values[i] = attrValueSet[i].OID.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_GeneralizedTime)
                {
                    values[i] = attrValueSet[i].GeneralizedTime.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_UtcTime)
                {
                    values[i] = attrValueSet[i].UTCTime.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_Integer)
                {
                    values[i] = attrValueSet[i].BigInteger.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_Boolean)
                {
                    values[i] = Convert.ToString(attrValueSet[i].Boolean);
                }
                else
                {
                    values[i] = Debug.ToString(attrValueSet[i].DataBytes);
                }
            }

            this.Name_Renamed  = type.ToString();
            this.Value_Renamed = values.Length == 1 ? values[0] : Arrays.ToString(values);
        }
Exemplo n.º 6
0
        public override ScalarObject MatchGet(ObjectIdentifier id)
        {
            ScalarObject result = base.MatchGet(id);
            if (result == null && id.ToString().Contains(SNMPHelper.TestTreePath))
            {
                logger.InfoFormat("Create OID id: {0}", id);
                IOidUnit oidUnit = CreateOidUnit(id);
                oidUnit.ValueChanged +=
                    (sender, args) => { if (TestValueChanged != null) TestValueChanged.Invoke(sender, args); };

                result = (ScalarObject) oidUnit;
                _elements.Add(result);
            }
            return result;
        }
 public void TestConversion()
 {
     var o = new ObjectIdentifier(".1.3.6.1.2.1.1.1.0");
     Assert.AreEqual(".1.3.6.1.2.1.1.1.0", o.ToString());
 }
Exemplo n.º 8
0
        /// <summary>
        /// Populates a DataGridView with the ARP Cache.
        /// </summary>
        /// <returns></returns>
        public DataTable DataTableARP()
        {
            // OID Value
            ObjectIdentifier oidArpTable = new ObjectIdentifier(".1.3.6.1.2.1.3.1");

            // Where our SNMP data will go.
            Dictionary <string, ISnmpData> dictResults;
            DataTable tableResults = new DataTable();

            tableResults.Columns.Add("Interface");
            tableResults.Columns.Add("Physical Address");
            tableResults.Columns.Add("Network Address");
            string szBaseOid = oidArpTable.ToString() + ".1.";

            try
            {
                dictResults = this.GetOidWalk(oidArpTable);
            }
            catch (Exception)
            {
                throw;
            }


            //
            // Determine the number of rows.
            // Get a list of all the interfaces
            ArrayList dRowArray  = new ArrayList();
            int       dRowsAdded = 0;

            foreach (string s in dictResults.Keys)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid    = s.Split('.');
                int      dDataTypeId = Convert.ToInt32(szRowOid[9]);
                string   szRowIdPart = szRowOid[11] + "." + szRowOid[12] + "."
                                       + szRowOid[13] + "." + szRowOid[14] + "." + szRowOid[15]
                                       + "." + szRowOid[16];

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Contains(szRowIdPart))
                {
                    dRowArray.Add(szRowIdPart);
                    dRowsAdded++;
                }
            }

            // iterate over SNMP arp cache entries.
            int rowCurrent = 0;

            while (rowCurrent < dRowArray.Count)
            {
                string szRowCurrentOid = dRowArray[rowCurrent].ToString();
                string szInterface     = string.Empty;
                int    dIfIndex        = ((Integer32)dictResults[szBaseOid + 1 + "." + szRowCurrentOid]).ToInt32();
                deviceInterfaces.TryGetValue(dIfIndex, out szInterface);
                string szPhysicalAddr = Util.ParseSNMPMac(
                    ((OctetString)dictResults[szBaseOid + 2 + "." + szRowCurrentOid]).ToBytes(),
                    2);
                string szIpAddr = ((IP)dictResults[szBaseOid + 3 + "." + szRowCurrentOid]).ToString();

                tableResults.Rows.Add(szInterface, szPhysicalAddr, szIpAddr);
                rowCurrent++;
            }
            return(tableResults);
        }
Exemplo n.º 9
0
 public static int GetObjectIndex(ObjectIdentifier id)
 {
     string[] dots = id.ToString().Split('.');
     return Convert.ToInt32(dots.Last());
 }
Exemplo n.º 10
0
        public static string GetStringOf(ObjectIdentifier id, IObjectRegistry objects)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            
            if (objects == null)
            {
                return id.ToString();
            }

            string result = objects.Tree.Search(id.ToNumerical()).AlternativeText;
            return string.IsNullOrEmpty(result) ? id.ToString() : result;
        }
Exemplo n.º 11
0
        public static DataTable ReadTable(
            VersionCode version,
            IPEndPoint endpoint,
            OctetString community,
            ObjectIdentifier table,
            int timeout,
            params uint[][] colonnesAPrendre)
        {
            string          strOIDTable  = table.ToString();
            List <Variable> lstVariables = new List <Variable>();
            int             nResult      = 0;

            if (colonnesAPrendre == null || colonnesAPrendre.Length == 0)
            {
                nResult = Walk(version, endpoint, community, table, lstVariables, timeout, WalkMode.WithinSubtree);
            }
            else
            {
                foreach (uint[] oidCol in colonnesAPrendre)
                {
                    List <Variable> lstTmp = new List <Variable>();
                    nResult = Walk(version, endpoint, community, new ObjectIdentifier(oidCol), lstTmp, timeout, WalkMode.WithinSubtree);
                    lstVariables.AddRange(lstTmp);
                }
            }

            //Création de la structure de la table
            DataTable  dataTable = new DataTable(strOIDTable);
            DataColumn colIndex  = new DataColumn("Index", typeof(string));

            dataTable.Columns.Add(colIndex);
            uint[] nOidTable = table.ToNumerical();
            Dictionary <string, DataRow> dicRows = new Dictionary <string, DataRow>();

            foreach (Variable variable in lstVariables)
            {
                string strOIDVariable = "";
                string strIndex       = "";
                uint[] nOidVariable   = variable.Id.ToNumerical();
                for (int nVar = 0; nVar < nOidVariable.Length; nVar++)
                {
                    if (nVar <= nOidTable.Length + 1)
                    {
                        strOIDVariable += "." + nOidVariable[nVar];
                    }
                    else
                    {
                        strIndex += nOidVariable[nVar] + ".";
                    }
                }
                if (strIndex.Length > 0)
                {
                    strIndex = strIndex.Substring(0, strIndex.Length - 1);
                }
                DataColumn col = dataTable.Columns[strOIDVariable];
                if (col == null)
                {
                    col = new DataColumn(strOIDVariable, variable.Data.GetTypeDotNet());
                    dataTable.Columns.Add(col);
                }
                DataRow row = null;
                if (!dicRows.TryGetValue(strIndex, out row))
                {
                    row               = dataTable.NewRow();
                    row["Index"]      = strIndex;
                    dicRows[strIndex] = row;
                    dataTable.Rows.Add(row);
                }
                row[strOIDVariable] = variable.Data.ConvertToTypeDotNet();
            }
            return(dataTable);
        }
 public void TestToString()
 {
     var transmission = new ObjectIdentifier(new uint[] {1, 3, 6, 1, 2, 1, 10});
     //Assert.AreEqual(".iso.org.dod.internet.mgmt.mib-2.transmission",
     //                transmission.ToString(DefaultObjectRegistry.Instance));
     Assert.AreEqual(".1.3.6.1.2.1.10", transmission.ToString());
 }
        public void TestConversion()
        {
            var o = new ObjectIdentifier("1.3.6.1.2.1.1.1.0");

            Assert.Equal("1.3.6.1.2.1.1.1.0", o.ToString());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Walks an OID (within subtree) and tries to map it into a table layout.
        /// </summary>
        /// <param name="requestedOid"></param>
        /// <returns></returns>
        private Dictionary <int, object>[] OidWalkTable(ObjectIdentifier requestedOid, int oidRowId = 0)
        {
            List <Variable> oidResults = new List <Variable>();
            string          szBaseOid  = requestedOid.ToString();

            // Walk the OID.
            try
            {
                if (snmpVersion == VersionCode.V1)
                {
                    Messenger.Walk(snmpVersion, snmpEndpoint, snmpCommunity, requestedOid, oidResults, snmpTimeout, WalkMode.WithinSubtree);
                }
                else if (snmpVersion == VersionCode.V2)
                {
                    Messenger.BulkWalk(snmpVersion, snmpEndpoint, snmpCommunity, requestedOid, oidResults, snmpTimeout, 255, WalkMode.WithinSubtree, null, null);
                }
                else
                {
                    IList <Variable> result        = new List <Variable>();
                    Discovery        snmpDiscovery = Messenger.NextDiscovery;
                    ReportMessage    snmpRepMsg    = snmpDiscovery.GetResponse(snmpTimeout, snmpEndpoint);
                    Messenger.BulkWalk(snmpVersion, snmpEndpoint, snmpUser, requestedOid, result, snmpTimeout, 255, WalkMode.WithinSubtree, snmpPriv, snmpRepMsg);

                    oidResults = new List <Variable>(result);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //
            // Determine the numbe of rows.
            // Get a list of all the interfaces
            ArrayList dRowArray  = new ArrayList();
            int       dRowsAdded = 0;

            foreach (Variable v in oidResults)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid = v.Id.ToString().Split('.');
                if (oidRowId == 0)
                {
                    oidRowId = szRowOid.Length - 1;
                }
                int dThisRowId = Convert.ToInt32(szRowOid[oidRowId]);

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Contains(dThisRowId))
                {
                    dRowArray.Add(dThisRowId);
                    dRowsAdded++;
                }
            }


            //
            // Loop over each row, add object ID and value to a dictionary array.
            Dictionary <int, object>[] results = new Dictionary <int, object> [dRowArray.Count];
            int dCurrentRow = 0;

            foreach (int rowId in dRowArray)
            {
                List <Variable> listRowCells = oidResults.FindAll(o => o.Id.ToString().Split('.').Last() == rowId.ToString());
                foreach (Variable v in listRowCells)
                {
                    string[] szOidParts = v.Id.ToString().Remove(0, 1).Split('.');
                    int      dObjectId  = Convert.ToInt32(szOidParts[szOidParts.Length - 2]);

                    if (results[dCurrentRow] == null)
                    {
                        results[dCurrentRow] = new Dictionary <int, object>();
                    }
                    results[dCurrentRow].Add(dObjectId, v.Data);
                }
                dCurrentRow++;
            }

            return(results);
        }
Exemplo n.º 15
0
        protected IOidUnit CreateOidUnit(ObjectIdentifier id)
        {
            var oidUnit = new OidUnit(id.ToString(), new OctetString("NULL"));

            return oidUnit;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Populates the route DataGridView.
        /// </summary>
        /// <returns></returns>
        public DataTable DataTableRoutes()
        {
            // OID Value
            ObjectIdentifier oidRouteTableCidr = new ObjectIdentifier(".1.3.6.1.2.1.4.24.4");

            // Where our SNMP data will go.
            Dictionary <string, ISnmpData> dictResults;
            DataTable tableResults = new DataTable();

            tableResults.Columns.Add("Destination");
            tableResults.Columns.Add("Mask");
            tableResults.Columns.Add("Next Hop");
            tableResults.Columns.Add("Metric");
            tableResults.Columns.Add("Interface");
            tableResults.Columns.Add("Protocol");
            tableResults.Columns.Add("Type");
            tableResults.Columns.Add("Age");

            string szBaseOid = oidRouteTableCidr.ToString() + ".1.";

            try
            {
                dictResults = this.GetOidWalk(oidRouteTableCidr);
            }
            catch (Exception)
            {
                throw;
            }

            //
            // Determine the number of rows.
            // Get a list of all the interfaces
            ArrayList dRowArray  = new ArrayList();
            int       dRowsAdded = 0;

            foreach (string s in dictResults.Keys)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid    = s.Split('.');
                int      dDataTypeId = Convert.ToInt32(szRowOid[11]);
                string   szRowIdPart = szRowOid[12] + "."
                                       + szRowOid[13] + "." + szRowOid[14] + "." + szRowOid[15] + "."
                                       + szRowOid[16] + "." + szRowOid[17] + "." + szRowOid[18] + "."
                                       + szRowOid[19] + "." + szRowOid[20] + "." + szRowOid[21] + "."
                                       + szRowOid[22] + "." + szRowOid[23] + "." + szRowOid[24];

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Contains(szRowIdPart))
                {
                    dRowArray.Add(szRowIdPart);
                    dRowsAdded++;
                }
            }

            // Now we have the row parts, get the values.
            int rowCurrent = 0;
            int dRowCount  = dRowArray.Count;

            while (rowCurrent < dRowCount)
            {
                string   szRowCurrentOid = dRowArray[rowCurrent].ToString();
                string   szInterface = string.Empty, szDestination = string.Empty, szMask = string.Empty, szNextHop = string.Empty, szMetric = string.Empty, szRouteProtocol = string.Empty, szRouteType = string.Empty, szRouteAge = string.Empty;
                TimeSpan tRouteAge = TimeSpan.Zero;
                int      dIfIndex  = 0;

                if (dictResults.Keys.Contains(szBaseOid + 5 + "." + szRowCurrentOid))
                {
                    dIfIndex = ((Integer32)dictResults[szBaseOid + 5 + "." + szRowCurrentOid]).ToInt32();
                }
                else
                {
                    continue;
                }
                deviceInterfaces.TryGetValue(dIfIndex, out szInterface);

                try
                {
                    if (dictResults.Keys.Contains(szBaseOid + 1 + "." + szRowCurrentOid))
                    {
                        szDestination = ((IP)dictResults[szBaseOid + 1 + "." + szRowCurrentOid]).ToString();
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 2 + "." + szRowCurrentOid))
                    {
                        szMask = ((IP)dictResults[szBaseOid + 2 + "." + szRowCurrentOid]).ToString();
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 4 + "." + szRowCurrentOid))
                    {
                        szNextHop = ((IP)dictResults[szBaseOid + 4 + "." + szRowCurrentOid]).ToString();
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 11 + "." + szRowCurrentOid))
                    {
                        szMetric = ((Integer32)dictResults[szBaseOid + 11 + "." + szRowCurrentOid]).ToString();
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 7 + "." + szRowCurrentOid))
                    {
                        szRouteProtocol = Util.RouteProtocolToString(((Integer32)dictResults[szBaseOid + 7 + "." + szRowCurrentOid]).ToString());
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 6 + "." + szRowCurrentOid))
                    {
                        szRouteType = Util.RouteTypeToString(((Integer32)dictResults[szBaseOid + 6 + "." + szRowCurrentOid]).ToString());
                    }

                    if (dictResults.Keys.Contains(szBaseOid + 8 + "." + szRowCurrentOid))
                    {
                        tRouteAge = TimeSpan.FromSeconds(((Integer32)dictResults[szBaseOid + 8 + "." + szRowCurrentOid]).ToInt32());
                    }
                }
                catch {
                    throw;
                }
                tableResults.Rows.Add(szDestination, szMask, szNextHop, szMetric, szInterface, szRouteProtocol, szRouteType, tRouteAge.ToString(@"d\d\ hh\h\ mm\m\ ss\s"));

                rowCurrent++;
            }

            return(tableResults);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Dictionary containing IP addresses bound to interfaces.
        /// </summary>
        /// <returns></returns>
        public Dictionary <int, ArrayList> GetIPInterfaces()
        {
            ObjectIdentifier oidAddrTable = new ObjectIdentifier(".1.3.6.1.2.1.4.20.1");
            string           szBaseOid    = oidAddrTable.ToString() + ".";
            Dictionary <string, ISnmpData> dictResults;
            Dictionary <int, ArrayList>    dictIpAddr = new Dictionary <int, ArrayList>();

            try
            {
                dictResults = GetOidWalk(oidAddrTable);
            }
            catch (Exception)
            {
                throw;
            }

            //
            // Determine the number of rows.
            // Get a list of all the interfaces
            ArrayList dRowArray  = new ArrayList();
            int       dRowsAdded = 0;

            foreach (string s in dictResults.Keys)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid    = s.Split('.');
                int      dDataTypeId = Convert.ToInt32(szRowOid[9]);
                string   szRowIdPart = szRowOid[11] + "." + szRowOid[12] + "." + szRowOid[13] + "." + szRowOid[14];

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Contains(szRowIdPart))
                {
                    dRowArray.Add(szRowIdPart);
                    dRowsAdded++;
                }
            }

            // Now we have the row parts, get the values.
            int rowCurrent = 0;
            int dRowCount  = dRowArray.Count;

            while (rowCurrent < dRowCount)
            {
                string szRowCurrentOid = dRowArray[rowCurrent].ToString();
                int    dIfIndex        = ((Integer32)dictResults[szBaseOid + 2 + "." + szRowCurrentOid]).ToInt32();
                string szIPAddr        = ((IP)dictResults[szBaseOid + 1 + "." + szRowCurrentOid]).ToString();

                if (dictIpAddr.Keys.Contains(dIfIndex))
                {
                    ArrayList al = dictIpAddr[dIfIndex];
                    al.Add(szIPAddr);
                    dictIpAddr[dIfIndex] = al;
                }
                else
                {
                    ArrayList al = new ArrayList();
                    al.Add(szIPAddr);
                    dictIpAddr.Add(dIfIndex, al);
                }

                rowCurrent++;
            }

            return(dictIpAddr);
        }
Exemplo n.º 18
0
            public string OidEquipo(string name)
            {
                ObjectIdentifier oid_base = new ObjectIdentifier(BaseOid + ".2");

                var var_equipo_name = this.MibObjects.Where(obj => obj.Variable.Id.ToString().StartsWith(oid_base.ToString()) &&
                                                            obj.Variable.Data.ToString() == name);

                if (var_equipo_name != null && var_equipo_name.Count() > 0)
                {
                    MibObject obj_equipo_name = var_equipo_name.ToList()[0];
                    string    oid_equipo_name = obj_equipo_name.Variable.Id.ToString();
                    int       index           = oid_equipo_name.LastIndexOf(".");
                    string    ret             = oid_equipo_name.Substring(index, oid_equipo_name.Length - index);
                    return(ret);
                }
                return("");
            }
Exemplo n.º 19
0
        /// <summary>
        /// Populates the CDP DataGridView
        /// </summary>
        public DataTable DataTableCDP()
        {
            // OID Value
            ObjectIdentifier oidCDPTable = new ObjectIdentifier(".1.3.6.1.4.1.9.9.23.1.2.1");
            string           szBaseOid   = oidCDPTable.ToString() + ".1.";

            Dictionary <string, ISnmpData> dictResults;
            DataTable tableResults = new DataTable();

            tableResults.Columns.Add("Interface");
            tableResults.Columns.Add("Hostname");
            tableResults.Columns.Add("IP Address");
            tableResults.Columns.Add("Platform");
            tableResults.Columns.Add("Version");
            tableResults.Columns.Add("Native VLAN");
            try
            {
                dictResults = this.GetOidWalk(oidCDPTable);
            }
            catch (Exception)
            {
                throw;
            }

            //
            // Determine the numbe of rows.
            // Get a list of all the interfaces
            Dictionary <int, int> dRowArray = new Dictionary <int, int>();
            int dRowsAdded = 0;

            foreach (string s in dictResults.Keys)
            {
                // Get the row ID from the penultimate value.
                string[] szRowOid   = s.Split('.');
                int      dThisRowId = Convert.ToInt32(szRowOid[szRowOid.Length - 1]);

                // Build an array of row IDs, since they're not always sequential.
                if (!dRowArray.Keys.Contains(dThisRowId))
                {
                    dRowArray.Add(dThisRowId, dThisRowId = Convert.ToInt32(szRowOid[szRowOid.Length - 2]));
                    dRowsAdded++;
                }
            }

            //
            // .1.3.6.1.4.1.9.9.23.1.2.1.1.3.8.1
            // ...
            // 3 = data type?
            // 8 = interface ID
            // 1 = device ID?
            foreach (KeyValuePair <int, int> row in dRowArray)
            {
                string szInterface = string.Empty;
                deviceInterfaces.TryGetValue(row.Value, out szInterface);

                string szHostname = ((OctetString)dictResults[szBaseOid + 6 + "." + row.Value + "." + row.Key]).ToString();

                // IP address of device.
                string szAddress    = string.Empty;
                int    dAddressType = ((Integer32)dictResults[szBaseOid + 3 + "." + row.Value + "." + row.Key]).ToInt32();
                if (dAddressType == 1)
                {
                    byte[] bAddress = ((OctetString)dictResults[szBaseOid + 4 + "." + row.Value + "." + row.Key]).ToBytes();
                    szAddress = bAddress[2] + "." + bAddress[3] + "." + bAddress[4] + "." + bAddress[5];
                }
                // Platform
                string szPlatform = ((OctetString)dictResults[szBaseOid + 8 + "." + row.Value + "." + row.Key]).ToString();
                szPlatform = szPlatform.Replace("cisco ", string.Empty).Trim();

                // Version
                string szVersion    = "Unknown";
                string szVersionTmp = ((OctetString)dictResults[szBaseOid + 5 + "." + row.Value + "." + row.Key]).ToString();
                Match  regexVersion = Regex.Match(szVersionTmp, "Version ([0-9A-Za-z.()]{2,})");
                if (regexVersion.Success)
                {
                    szVersion = regexVersion.Value.ToString().Replace("Version ", string.Empty);
                }

                // Native VLAN.
                string szNativeVlan = ((Integer32)dictResults[szBaseOid + 11 + "." + row.Value + "." + row.Key]).ToString();

                tableResults.Rows.Add(szInterface, szHostname, szAddress, szPlatform, szVersion, szNativeVlan);
            }
            return(tableResults);
        }
        public void TestToString()
        {
            var transmission = new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 2, 1, 10 });

            Assert.Equal("1.3.6.1.2.1.10", transmission.ToString());
        }
Exemplo n.º 21
0
 public SNMPReceivedArgs(ObjectIdentifier oid, ISnmpData data)
 {
     OID  = oid.ToString();
     Data = data.ToString();
 }
Exemplo n.º 22
0
 public static IObservable <IEnumerable <object> > GetObjects(this PluginContext context, ObjectIdentifier id)
 {
     return(context.PerFrame
            .StartWith(0)
            .Select(_ =>
                    (IEnumerable <object>)context.Reflection.CallStatic(typeof(ObjectTagRegistry).FullName, "GetObjectsWithTag", id.ToString())));
 }
Exemplo n.º 23
0
 public override string ToString() => ObjectIdentifier.ToString();