在我的虚拟盒子中,有四个接口,环回接口如下所示。 eth0,eth1,eth2,eth3,lo。
VirtualBox:~/pysnmp# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:e1:eb:b9 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:10:b8:4b brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:94:00:83 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:62:2b:9f brd ff:ff:ff:ff:ff:ff
当我尝试使用pysnmp nextcmd 获取接口信息时,它始终仅显示两个接口 eth0,lo 。
使用此示例:
from pysnmp.hlapi import *
for (errorIndication,
errorStatus,
errorIndex,
varBinds) in nextCmd(SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')),
ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')),
ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')),
ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
lexicographicMode=False):
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1][0] or '?'))
break
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
输出:
root@VirtualBox:~/pysnmp# python tutorial.py
IF-MIB::ifDescr.1 = lo
IF-MIB::ifType.1 = softwareLoopback
IF-MIB::ifMtu.1 = 16436
IF-MIB::ifSpeed.1 = 10000000
IF-MIB::ifPhysAddress.1 =
IF-MIB::ifType.1 = softwareLoopback
IF-MIB::ifDescr.2 = eth0
IF-MIB::ifType.2 = ethernetCsmacd
IF-MIB::ifMtu.2 = 1500
IF-MIB::ifSpeed.2 = 100000000
IF-MIB::ifPhysAddress.2 = 00:12:79:62:f9:40
IF-MIB::ifType.2 = ethernetCsmacd
其余接口如何?没有显示?有什么想法吗?
答案 0 :(得分:1)
要获取本地计算机(虚拟框)中的接口,请按如下所示修改逻辑。
CommunityData('public', mpModel=0), < "Community string is what you configured in your local machine refer snmd.conf file">
UdpTransportTarget(('localhost', 161)). <Target IP address is our local host>
答案 1 :(得分:0)
const rootReducer = combineReducers({
routing: routeReducer,
results});
。目标IP地址是demo.snmplabs.com。它正在从该IP地址获取接口名称。