Guten Morgen zusammen,
ich versuche mit einem Teracom - TCW122B-CM via SNMP eine Verbindung aufzubauen. Im Vorfeld habe ich folgendes gemacht:
SNMP Configuration: Enable
SNMP Port : 161
Write community: private
Read community: public
Um das Gerät per C# anzusprechen, verwende ich die bereits vielfach hier im Forum erwähnte Lib von https://www.snmpsharpnet.com/.
Ich habe mich hierzu für das einfachste Beispiel entschieden (https://www.snmpsharpnet.com/?page_id=102):
string host = "10.17.0.102";
string community = "public";
SimpleSnmp snmp = new SimpleSnmp(host, community);
if (!snmp.Valid)
{
Console.WriteLine("SNMP agent host name/ip address is invalid.");
return;
}
Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.4.1.38783.1.1.0" });
if (result == null)
{
Console.WriteLine("No results received.");
return;
}
foreach (var kvp in result)
{
Console.WriteLine("{0}: {1} {2}", kvp.Key.ToString(),
SnmpConstants.GetTypeName(kvp.Value.Type),
kvp.Value.ToString());
}
_11. Control and monitoring using SNMP
TCW122B-CM can be configured and monitored through SNMP (Simple Network Management
Protocol). This could be done using every SNMP v.1 compatible program. Parameters that can
be changed, are grouped according to their functions in the tables below. To obtain a valid
OID number it is necessary to replace the “x” symbol with ”1.3.6.1.4.1.38783”. To save the
changes configurationSaved (OID x.3.13.0) should be set to "1".
11.1. Product
OID / Name / Access / Description / Syntax
x.1.1.0 / name / read-only / Device name / String_
Das result-Objekt ist jedoch immer null. Ich laufe immer in diese If-Abfrage:
if (result == null)
{
Console.WriteLine("No results received.");
return;
}
Jemand eine Idee, wo der Fehler liegen könnte?
Vielen Dank im Voraus!
...dann wären doch die nächsten logischen Schritte
* zu testen ob Daten übertragen werden
* es mal mit einer SNMP-Nummernkette zu probieren wo das Gerät bekanntermasßen antwortet
Hallo Witte,
danke für Deine Antwort. Wie soll ich denn testen, ob Daten übertragen werden? Das ist ja generell mein Versuch. Ich habe mal eine SNMP Nummernkette aufgebaut, wobei die Angaben (bspw. "1.3.6.1.4.1.38783.1.1.0") ja aus dem Handbuch des Geräts stammen:
Daher sieht mein Sourcecode dzt. so aus:
internal class SnmpConnector
{
internal static void Connect()
{
string host = "10.17.0.102";
string community = "public";
SimpleSnmp snmp = new SimpleSnmp(host, community);
if (!snmp.Valid)
{
Console.WriteLine("SNMP agent host name/ip address is invalid.");
return;
}
for (int i = 39999; i > 0; i--)
{
foreach (var x in OidsSuffixe)
{
var completeOid = "1.3.6.1.4.1."+ i +"." + x;
Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, new string[] { completeOid });
if (result == null)
{
Console.WriteLine("No results received with OID: " + completeOid);
continue;
}
foreach (var kvp in result)
{
// Result ist immer null, in diese Schleife kommt man nie rein.
Console.WriteLine("{0}: {1} {2}", kvp.Key.ToString(),
SnmpConstants.GetTypeName(kvp.Value.Type),
kvp.Value.ToString());
}
}
}
}
private static string[] OidsSuffixe // entnommen aus den Handbuch des Thermometers
{
get
{
return new string[]
{
"1.1.0",
"1.2.0",
"1.3.0",
"2.1.1.0",
"2.1.2.0",
"2.1.3.0",
"2.1.4.0",
"2.1.5.0",
"2.1.6.0",
"2.1.7.0",
"2.4.1.0",
"2.4.2.0",
"2.4.3.0",
"2.4.4.0",
"2.4.5.0",
"2.4.6.0",
"2.5.1.1.0",
"2.5.1.2.0",
"2.5.1.3.0",
"2.5.1.4.0",
"2.5.2.1.0",
"2.5.2.2.0",
"2.5.2.3.0",
"2.5.2.4.0",
"2.6.1.1.0",
"2.6.1.2.0",
"2.6.1.3.0",
"2.6.1.4.0",
"2.6.2.1.0",
"2.6.2.2.0",
"2.6.2.3.0",
"2.6.2.4.0",
"2.7.1.1.0",
"2.7.1.2.0",
"2.7.1.3.0",
"2.7.1.4.0",
"2.7.1.5.0",
"2.8.1.0",
"2.8.2.0",
"2.8.3.0",
"2.8.4.0",
"2.9.1.0",
"2.9.2.0",
"2.9.3.0",
"2.9.4.0",
"2.10.1.0",
"3.1.0",
"3.2.0",
"3.3.0",
"3.4.0",
"3.5.0",
"3.6.0",
"3.7.0",
"3.8.0",
"3.9.0",
"3.10.0",
"3.11.0",
"3.12.0",
"3.13.0",
"3.14.0"
};
}
}
}
Ich meinte dass du mal mit Wireshark den Datenverkehr mitschneiden sollst um festzustellen ob Anfragen von Rechner aus gesendet werden und Antworten vom Thermometer kommen. Des weitreren gibt es doch sicherlich Oids die so einfach sind dass jedes Gerät antwortet wie z.B. Versionsnummer o.ä.