doubiao1734 2012-06-05 16:00
浏览 57
已采纳

使用PHP解析SNMP响应

I'm currently successfully reading out several properties on our switches over SNMP with php. Now i'm looking at making the resulting output of snmpget and snmpwalk actually usefull for the consumers of our API's.

Problem is that the responses look like this: INTEGER: up(1) and INTEGER: 10103 ...

Is there any convention/standard on how to parse this response format or is the response vendor specific for each device we are trying to read?

Is there by any chance already a PHP library, function or extension that can cast these responses in php native variables or at least something usefull that we can work with?


UPDATE:

I've found out a few new things namely that there are indeed several libraries in php that can parse binary ASN.1 strings which basically are BER encoded strings if i'm right. Problem is that i can't seem to find a way to get the binary data from the devices with php ...

  • 写回答

2条回答 默认 最新

  • dooo61733 2012-06-08 07:55
    关注

    I'm not sure about your particular PHP methods, but the difference between your two INTEGER examples is likely to be whether your system has an SNMP MIB corresponding to the OID (e.g. to determine that 1 means "up").

    If you only want the integers, you should be able to pass a parameter to your get or walk command. For example, net-snmp's snmpget or snmpwalk commands will take -Oe to remove symbolic labels. From the manpage:

                  $ snmpget -c public -v 1 localhost ipForwarding.0
                  IP-MIB::ipForwarding.0 = INTEGER: forwarding(1)
                  $ snmpget -c public -v 1 -Oe localhost ipForwarding.0
                  IP-MIB::ipForwarding.0 = INTEGER: 1
    

    If you are parsing net-snmp output, I recommend reading the snmpcmd man page as it has a lot of output options that will interest you especially the display of other types such as timeticks and strings.

    If you do want to retrieve SNMP in PHP you could look at how Cacti does it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵