@@ -7,6 +7,11 @@ for C# and .NET.
7
7
Basic SNMP operations (GET, SET and so on) you learn from elsewhere can be
8
8
easily translated to C# SNMP function calls.
9
9
10
+ .. note ::
11
+
12
+ The equivalent Net-SNMP command line is provided for each operation, so you
13
+ can compare the two.
14
+
10
15
GET Operation
11
16
-------------
12
17
The following code shows how to send an SNMP v1 GET message to an SNMP agent
@@ -28,6 +33,14 @@ minute), and throw an exception (``TimeoutException``). If any error occurs, an
28
33
The result returned is a list that matches the list of ``Variable `` objects
29
34
sent. The ``Variable `` in this list contains the value of the OID.
30
35
36
+ .. note ::
37
+
38
+ The equivalent Net-SNMP command line is
39
+
40
+ .. code-block :: bash
41
+
42
+ snmpget -v 1 -c public -t 60 192.168.1.2:161 1.3.6.1.2.1.1.1.0
43
+
31
44
SET Operation
32
45
-------------
33
46
The following code shows how to send an SNMP v1 SET message to an SNMP agent
@@ -42,6 +55,14 @@ located at ``192.168.1.2`` and set the value of OID ``1.3.6.1.2.1.1.6.0`` to
42
55
new List <Variable >{new Variable (new ObjectIdentifier (" 1.3.6.1.2.1.1.6.0" ), new OctetString (" Shanghai" ))},
43
56
60000 );
44
57
58
+ .. note ::
59
+
60
+ The equivalent Net-SNMP command line is
61
+
62
+ .. code-block :: bash
63
+
64
+ snmpset -v 1 -c public -t 60 192.168.1.2:161 1.3.6.1.2.1.1.6.0 s " Shanghai"
65
+
45
66
GET-NEXT Operation
46
67
------------------
47
68
The following code shows how to send an SNMP v1 GET-NEXT message to an SNMP
@@ -52,7 +73,7 @@ agent located at ``192.168.1.2`` and query on OID ``1.3.6.1.2.1.1.1.0``,
52
73
GetNextRequestMessage message = new GetNextRequestMessage (0 ,
53
74
VersionCode .V1 ,
54
75
new OctetString (" public" ),
55
- new List <Variable >{new Variable (new ObjectIdentifier (" 1.3.6.1.2.1.1.6 .0" ))});
76
+ new List <Variable >{new Variable (new ObjectIdentifier (" 1.3.6.1.2.1.1.1 .0" ))});
56
77
ISnmpMessage response = message .GetResponse (60000 , new IPEndPoint (IPAddress .Parse (" 192.168.1.2" ), 161 ));
57
78
if (response .Pdu ().ErrorStatus .ToInt32 () != 0 )
58
79
{
@@ -64,6 +85,14 @@ agent located at ``192.168.1.2`` and query on OID ``1.3.6.1.2.1.1.1.0``,
64
85
65
86
var result = response .Pdu ().Variables ;
66
87
88
+ .. note ::
89
+
90
+ The equivalent Net-SNMP command line is
91
+
92
+ .. code-block :: bash
93
+
94
+ snmpgetnext -v 1 -c public -t 60 192.168.1.2:161 1.3.6.1.2.1.1.1.0
95
+
67
96
GET-BULK Operation
68
97
------------------
69
98
The following code shows how to send an SNMP v2 GET-BULK message to an SNMP
@@ -76,7 +105,7 @@ agent located at ``192.168.1.2`` and query on OID ``1.3.6.1.2.1.1.1.0``,
76
105
new OctetString (" public" ),
77
106
0 ,
78
107
10 ,
79
- new List <Variable >{new Variable (new ObjectIdentifier (" 1.3.6.1.2.1.1.6 .0" ))});
108
+ new List <Variable >{new Variable (new ObjectIdentifier (" 1.3.6.1.2.1.1.1 .0" ))});
80
109
ISnmpMessage response = message .GetResponse (60000 , new IPEndPoint (IPAddress .Parse (" 192.168.1.2" ), 161 ));
81
110
if (response .Pdu ().ErrorStatus .ToInt32 () != 0 )
82
111
{
@@ -88,6 +117,14 @@ agent located at ``192.168.1.2`` and query on OID ``1.3.6.1.2.1.1.1.0``,
88
117
89
118
var result = response .Pdu ().Variables ;
90
119
120
+ .. note ::
121
+
122
+ The equivalent Net-SNMP command line is
123
+
124
+ .. code-block :: bash
125
+
126
+ snmpbulkget -v 2c -c public -t 60 -Cn0 -Cr10 192.168.1.2:161 1.3.6.1.2.1.1.1.0
127
+
91
128
Walk Operation
92
129
--------------
93
130
Walk is not an atomic operation. That means, it utilizes several GET-NEXT (SNMP
@@ -105,6 +142,14 @@ walk on an SNMP agent located at ``192.168.1.2`` starting at ``1.3.6.1.2.1.1``,
105
142
60000 ,
106
143
WalkMode .WithinSubtree );
107
144
145
+ .. note ::
146
+
147
+ The equivalent Net-SNMP command line is
148
+
149
+ .. code-block :: bash
150
+
151
+ snmpwalk -v 1 -c public -t 60 192.168.1.2:161 1.3.6.1.2.1.1
152
+
108
153
The result returned contains a list of all available OIDs (as ``Variable ``) in
109
154
this SNMP agent that under tree node of ``1.3.6.1.2.1.1 ``.
110
155
@@ -131,6 +176,14 @@ built upon GET-BULK operations and provide better performance.
131
176
null ,
132
177
null );
133
178
179
+ .. note ::
180
+
181
+ The equivalent Net-SNMP command line is
182
+
183
+ .. code-block :: bash
184
+
185
+ snmpbulkwalk -v 2c -c public -t 60 -Cn0 -Cr10 192.168.1.2:161 1.3.6.1.2.1.1
186
+
134
187
TRAP Operation
135
188
--------------
136
189
It is usually an SNMP agent that sends out TRAP messages. The following code
@@ -148,6 +201,14 @@ manager located at ``192.168.1.3``,
148
201
0 ,
149
202
new List <Variable >());
150
203
204
+ .. note ::
205
+
206
+ The equivalent Net-SNMP command line is
207
+
208
+ .. code-block :: bash
209
+
210
+ snmptrap -v 1 -c public 192.168.1.3:162 1.3.6.1.2.1.1 192.168.1.2 6 0 0
211
+
151
212
SNMP v2 and above introduces a simplified TRAP v2 message,
152
213
153
214
.. code-block :: csharp
@@ -160,6 +221,14 @@ SNMP v2 and above introduces a simplified TRAP v2 message,
160
221
0 ,
161
222
new List <Variable >());
162
223
224
+ .. note ::
225
+
226
+ The equivalent Net-SNMP command line is
227
+
228
+ .. code-block :: bash
229
+
230
+ snmptrap -v 2c -c public 192.168.1.3:162 " " 1.3.6.1.2.1.1
231
+
163
232
INFORM Operation
164
233
----------------
165
234
It is usually an SNMP agent that sends out INFORM messages. The following code
@@ -179,6 +248,14 @@ shows how to send an empty INFORM message to an SNMP manager located at
179
248
null ,
180
249
null );
181
250
251
+ .. note ::
252
+
253
+ The equivalent Net-SNMP command line is
254
+
255
+ .. code-block :: bash
256
+
257
+ snmpinform -v 2c -c -t 2 public 192.168.1.3:162 " " 1.3.6.1.2.1.1
258
+
182
259
The manager should send back a reply to this INFORM message. Otherwise, a
183
260
``TimeoutException `` occurs.
184
261
0 commit comments