当前位置:首页 > SNMP用VC开发
个GetReponse报文,并置error status为noSuchName, error index的值是错误变量在变量list中的位置。
2.如果被管设备上的协议实体收到的PDU中的变量对偶中的值,类型、长度不符和要求,则收到该PDU的协议实体产生一个GetReponse报文,并置error status为badValue, error index的值是错误变量在变量list中的位置。
3.如果需要产生的GetReponse报文长度超过了本地限制,则收到该PDU的协议实体产生一个GetReponse报文,并置error status为tooBig, error index的值是0。
4.如果是其他原因导致SET失败,则收到该PDU的协议实体产生一个
GetReponse报文,并置error status为genErr, error index的值是错误变量在变量list中的位置。
如果不符合上面任何情况,则agent将把管理变量设置收到的PDU中的相应值,这往往可以改变被管设备的运行状态。同时产生一个GetResponse PDU,其中error status置为noError,error index的值为0。
1.10. Trap PDU
Trap PDU的有如下的形式
Trap是被管设备遇到紧急情况时主动向网管站发送的消息。网管站收到trapPDU后要将起变量对偶表中的内容显示出来。一些常用的trap类型有冷、热启动,链路状态发生变化等。
4. SNMP MIB编译器的功能
MIB编译器是Agent开发的一个工具,一个Agent的开发者首先面对的是一个MIB文件,其中是用ASN.1描述的管理对象集。MIB编译器要把这个文件转换成相应的C语言源文件。MIB编译器可极大的提供Agent的开发效率。
用C#实现的简易mib browser 1.source code
using System;
using System.Text; using System.Net;
using System.Net.Sockets;
public class SimpleSNMP {
public static void Main(string[] argv) {
int commlength, miblength, datatype, datalength, datastart;
int uptime = 0; string output;
SNMP conn = new SNMP();
byte[] response = new byte[1024];
Console.WriteLine(\);
// Send sysName SNMP request
response = conn.get(\, argv[0], argv[1], \.1.2.1.1.5.0\);
if (response[0] == 0xff) {
Console.WriteLine(\, argv[0]);
return; }
// If response, get the community name and MIB lengths
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMP response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output = Encoding.ASCII.GetString(response, datastart, datalength);
Console.WriteLine(\
: {1}\,
datatype, output);
// Send a sysLocation SNMP request
response = conn.get(\, argv[0], argv[1], \.1.2.1.1.6.0\);
if (response[0] == 0xff) {
Console.WriteLine(\, argv[0]);
return; }
// If response, get the community name and MIB lengths
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMP response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output = Encoding.ASCII.GetString(response, datastart, datalength);
Console.WriteLine(\alue: {1}\, datatype, output);
// Send a sysContact SNMP request
response = conn.get(\, argv[0], argv[1], \.1.2.1.1.4.0\);
if (response[0] == 0xff) {
Console.WriteLine(\, argv[0]);
return; }
// Get the community and MIB lengths
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMP response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output = Encoding.ASCII.GetString(response, datastart, datalength);
Console.WriteLine(\lue: {1}\,
datatype, output);
// Send a SysUptime SNMP request
response = conn.get(\, argv[0], argv[1], \.1.2.1.1.3.0\);
if (response[0] == 0xff) {
Console.WriteLine(\, argv[0]);
return; }
// Get the community and MIB lengths of the response
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
// Extract the MIB data from the SNMp response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
// The sysUptime value may by a multi-byte integer // Each byte read must be shifted to the higher byte order
while(datalength > 0) {
uptime = (uptime << 8) + response[datastart++]; datalength--; }
共分享92篇相关文档