【问题标题】:PHP SNMP Warning: SNMP::get(): No response from 127.0.0.1PHP SNMP 警告:SNMP::get(): No response from 127.0.0.1
【发布时间】:2018-07-13 09:52:40
【问题描述】:

我正在尝试让 PHP SNMP 在 XAMPP PHP 7.1.9 上运行

我总是得到这个结果:Warning: SNMP::get(): No response from 127.0.0.1

这就是我所做的:

  1. 在 php.ini 上启用 php_snmp.dll
  2. 已安装 net-snmp-5.5.0-2.x64
  3. 添加了值为 C:\usr\share\snmp\mibs 的 windows 环境变量 MIBDIRS

我正在运行测试的代码:

<?php
    $session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
    $sysdescr = $session->get("sysDescr.0");
    echo "$sysdescr\n";
    $session->close();

我是新手,所以我不确定我错过了什么。

【问题讨论】:

  • 第 2 步不会为您提供在 Windows 上工作的 SNMP 代理,因此您的代码不会得到来自 127.0.0.1 的响应。
  • 这是哪个版本的 windows?
  • 我在 windows10 上,但我想我应该指出我也尝试在 ubuntu 上使用 php snmp 并且得到了相同的结果。

标签: php snmp


【解决方案1】:

问题出在 MIBDIRS 路径上。

我关注了 php 文档,它说: The Windows distribution of Net-SNMP contains support files for SNMP in the mibs directory. This directory should added to Windows' environment variables, as MIBDIRS, with the value being the full path to the mibs directory: e.g. c:\usr\mibs.

问题是我在我的 net-snmp 安装中找不到c:\usr\mibs,所以我改用了C:\usr\share\snmp\mibs

解决方案:

我尝试使用支持 snmp 的设备而不是 127.0.0.1 并在 cli 上运行 snmpget 并确认 net-snmp 安装确实有效。我想问题一定出在 php 用来运行 snmp 的路径上。

所以我使用where snmpget 检查命令路径,然后更改 MIBDIRS 环境值,结果为C:\usr\bin\snmpget.exe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多