第一范文网 - 专业文章范例文档资料分享平台

SNMP用VC开发

来源:用户分享 时间:2025/5/16 4:54:19 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

个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--; }

搜索更多关于: SNMP用VC开发 的文档
SNMP用VC开发.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c37hao4zpix6trx0166bj_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top