dface / snmp-packet
SNMP 数据包编解码器
dev-master
2018-01-03 15:03 UTC
Requires
- php: >=7.1
- infection/infection: dev-master
- sop/asn1: dev-master
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2024-08-25 23:27:04 UTC
README
SnmpPacket
注意:这是一个早期开发版本。
一个用于编解码 SNMP 数据包的 PHP 库。
此库的目标不是实现 SNMP 协议处理。它只是用于将 SNMP 消息从二进制字符串解码成 PHP 对象,反之亦然。
支持 SNMP 消息版本 v1、v2c 和 v3。
安装
composer require dface/snmp-packet
使用方法
在 ./examples/NaiveSnmpGet.php
中可以找到 snmpget
命令的简单示例。查看 prepareRequest()
来了解如何构建/编码消息,以及查看 processResponse()
来了解如何解码/处理它们。
消息编码的简单示例
// construct pdu: $bindings = new VarBindList( new VarBind(new Oid('1.3.6.1.2.1.1.3.0'), new NullValue()) ); $pdu = new GetRequestPDU(1, 0, 0, $bindings); // pack into the message: $message = new MessageV1(1, $this->community, $pdu); // take a binary to send it somewhere: $bin = $message->toBinary();
消息解码的简单示例
// decode message from binary: $message = MessageV1::fromBinary($bin); // take pdu: $pdu = $message->getPdu(); //check on errors: $err = $pdu->getErrorStatus(); // iterate over bindings: $bindings = $pdu->getVariableBindings()->getList(); foreach ($bindings as $var_bind) { printf("%s: %s\n", $var_bind->getOid(), $var_bind->getValue()); }