【问题标题】:Using SNMP retrieve IP and MAC addresses of directly connected machines to a SNMP Device使用 SNMP 将直接连接的机器的 IP 和 MAC 地址检索到 SNMP 设备
【发布时间】:2019-03-11 12:46:05
【问题描述】:

如何获取连接机器的IP和SNMP设备的Mac。

ARP 缓存未提供正确的详细信息。

【问题讨论】:

  • 你是想从编程语言的结果中还是从 shell 或 cmd 中得到这个?

标签: networking snmp


【解决方案1】:

Linux shell 命令示例(在撰写本文时没有其他语言或 Windows 的标签)

假设您要查询的机器确实运行 SNMP 守护程序(通常是 Linux 下 Net-SNMP 的 snmpd)并且您知道如何/被允许与其交谈(版本 1、2c 或 3 具有各种社区名称或v3 的用户名/密码/编码)您可以发出以下 SNMP 请求:

为了测试,我在一个 CentOS 7 虚拟机上启动了一个 snmpd,它的主地址是 192.168.174.128。

我选择端口 1610 而不是传统的 161,以免 sudo 或 setcap (snmpd)。 snmpd.conf文件内容超出本题范围。

这是IP的第一个

snmptable -v 2c -c private 192.168.174.128:1610 ipAddrTable 

SNMP table: IP-MIB::ipAddrTable

    ipAdEntAddr ipAdEntIfIndex ipAdEntNetMask ipAdEntBcastAddr ipAdEntReasmMaxSize
      127.0.0.1              1      255.0.0.0                0                   ?
  192.168.122.1              3  255.255.255.0                1                   ?
192.168.174.128              2  255.255.255.0                1                   ?

MAC 的第二条命令(仅打印 3 列)

snmptable -v 2c -c private 192.168.174.128:1610 ifTable | awk -c '{print $1 "\t" $2 "\t\t" $6}'
SNMP    table:      

ifIndex ifDescr     ifPhysAddress
1       lo          up
2       ens33       0:c:29:53:aa:c6
3       virbr0      52:54:0:e6:6b:2f
4       virbr0-nic      52:54:0:e6:6b:2f

当我们在 CentOS 7 下检查时,我们得到

ifconfig
ens33: ...  mtu 1500
    inet 192.168.174.128  netmask 255.255.255.0  broadcast 192.168.174.255
    inet6 ...
    ether 00:0c:29:53:aa:c6 netmask 255.0.0.0
    ...

lo: ...  mtu 65536
    inet 127.0.0.1
    ...

virbr0: ...  mtu 1500
    inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
    ether 52:54:00:e6:6b:2f ...
    ...

额外的shell命令:

snmptranslate -Oaf IF-MIB::ifTable
.iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable

snmptranslate -Oaf IP-MIB::ipAddrTable
.iso.org.dod.internet.mgmt.mib-2.ip.ipAddrTable

我不知道为什么/如果有一个表包含这两个信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 2013-09-13
    相关资源
    最近更新 更多