public void testGetTable() { SNMP_Agent agent = new SNMP_Agent("localhost", "public"); //tcpConnTable string oid = ".1.3.6.1.2.1.4.20.1"; //IPAddress IP = IPAddress.Parse("127.0.0.1"); var result = agent.GetTableRequest(SnmpVersion.Ver2, oid); Assert.IsNotNull(result); Assert.IsTrue(result.Count != 0); //Wyświetlanie tabeli foreach (var key in result) { var dictionary = key.Value; foreach (var KEY in dictionary) { Console.WriteLine("Column: " + KEY.Key + " Value: " + KEY.Value); } } }
public void testGetTable() { SNMP_Agent agent = new SNMP_Agent("127.0.0.1", "public"); //tcpConnTable string oid = ".1.3.6.1.2.1.6.13"; IPAddress IP = IPAddress.Parse("127.0.0.1"); var result = agent.GetTableRequest(SnmpVersion.Ver2, oid); Assert.IsNotNull(result); }
private void goButton_Click(object sender, EventArgs e) { //string address = AddressTextBox.Text; string OID = OIDTextBox.Text; string option = OperationsComboBox.Text; string type = string.Empty; //syntax string name = string.Empty; //object name string value = string.Empty; DataStore?dataStore; string ttt; switch (option) { case "Get": ttt = findLongestTrunk(listValue, OID); dataStore = FindRowOID(ttt); if (dataStore != null) { type = dataStore.Value.type; name = dataStore.Value.value; if (name == "system" || name == "interfaces" || name == "at" || name == "ip" || name == "icmp" || name == "tcp" || name == "udp" || name == "egp" || name == "snmp" || name == "host") { name = OIDTextBox.Text; type = string.Empty; } } var result = snmp_agent.GetRequest(SnmpVersion.Ver2, OID, IP); value = result.Pdu.VbList[0].Value.ToString(); // result.Pdu. // get(); if (value == "Null" || value == "NULL" || value == "null") { //result = snmp_agent.GetNextRequest(SnmpVersion.Ver2, OID, IP); //OIDTextBox.Text = result.Pdu.VbList[0].Oid.ToString(); MessageBox.Show("No such name error(127.0.0.1)", "", MessageBoxButtons.OK, MessageBoxIcon.Error); //result = snmp_agent.GetNextRequest(SnmpVersion.Ver2, OID, IP); //OIDTextBox.Text = result.Pdu.VbList[0].Oid.ToString(); } else { addRowToResultsTable(name, value, type, IP.ToString()); dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; } break; case "Get Next": var resultNext = snmp_agent.GetNextRequest(SnmpVersion.Ver2, OID, IP); value = resultNext.Pdu.VbList[0].Value.ToString(); OIDTextBox.Text = "." + resultNext.Pdu.VbList[0].Oid.ToString(); ttt = findLongestTrunk(listValue, OIDTextBox.Text); dataStore = FindRowOID(ttt); if (dataStore != null) { type = dataStore.Value.type; name = dataStore.Value.value; if (name == "system" || name == "interfaces" || name == "at" || name == "ip" || name == "icmp" || name == "tcp" || name == "udp" || name == "egp" || name == "snmp" || name == "host") { name = OIDTextBox.Text; type = string.Empty; } } addRowToResultsTable(name, value, type, IP.ToString()); dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; break; case "Get Table": int lengthRow = dataGridView2.Rows.Count; int lengthColumn = dataGridView2.ColumnCount; for (int i = (lengthRow - 1); i >= 0; i--) { dataGridView2.Rows.RemoveAt(i); } for (int i = (lengthColumn - 1); i >= 0; i--) { dataGridView2.Columns.RemoveAt(i); } List <string> nameColumns = new List <string>(); nameColumns = getTableColumnName(ref OID); foreach (var column in nameColumns) { dataGridView2.Columns.Add("Column" + i, column); i++; } var dictionary = snmp_agent.GetTableRequest(SnmpVersion.Ver2, OID); List <AsnType> Values = new List <AsnType>(); foreach (var key in dictionary) { var dictionary2 = key.Value; foreach (var KEY in dictionary2) { //Dodanie wartosci do listy Values.Add(KEY.Value); } } if (Values.Count > 0) { string[] table = new string[dataGridView2.ColumnCount]; dataGridView2.Rows.Add(Values.Count / dataGridView2.ColumnCount); for (int i = 0; i < dataGridView2.ColumnCount; i++) { for (int j = 0; j < Values.Count / dataGridView2.ColumnCount; j++) { int elementAt = i * dataGridView2.Rows.Count + j; dataGridView2.Rows[j].Cells[i].Value = Values.ElementAt(elementAt).ToString(); } } ; dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView2.Rows.Count - 1; } else { MessageBox.Show("No such name"); } //TODO: Stwórz kolumny (z pliku tekstowego wyszukaj nazwy kolumn zaczynając na OID, i ile ich jest, i odpowiednio podziel listę wartości break; default: break; } }