snmp命令行命令

NAME:snmptranslate 

snmptranslate - translate MIB OID names between numeric and textual forms

# 注释 :snmptranslate 命令可以在 MIB OID 在数字和文字名称之间进行转换


SYNOPSIS

snmptranslate [OPTIONS] OID [OID]...

# 注释 :snmptranslate 命令的格式是 snmptranslate [options] OID [oid]

# 注释 :从上面的格式可以看出,snmptranslate 一次可以转换多个 OID


DESCRIPTION

snmptranslate is an application that translates one or more SNMP object identifier values from their symbolic (textual) forms into their numerical forms (or vice versa).

OID is either a numeric or textual object identifier.

# 注释 :snmptranslate 是一个将一个或者多个 SNMP OID 从文字名称格式转换为数字格式的程序

# [oid] 可以是数字格式或者文字格式。

# 注意!snmptranslate 可以直接将数字格式的 oid 转换为名称格式,

# 但要把名称格式的 oid 转换为数字格式的 oid ,需要 -I 选项的配合。(参考 snmpcmd 和最后部分的例子)


OPTIONS

-D TOKEN[,...]

Turn on debugging output for the given TOKEN(s). Try ALL for extremely verbose output.

-h

Display a brief usage message and then exit.

-m MIBLIST

Specifies a colon separated list of MIB modules to load for this application. This overrides the environment variable MIBS.

The special keyword ALL is used to specify all modules in all directories when searching for MIB files. Every file whose name does not begin with "." will be parsed as if it were a MIB file.

-M DIRLIST

Specifies a colon separated list of directories to search for MIBs. This overrides the environment variable MIBDIRS.

-T TRANSOPTS

Provides control over the translation of the OID values. The following TRANSOPTS are available:

# 注释 :-T 选项用于控制转换的输出

-Td

Print full details of the specified OID.

# 注释 :-Td 表示输出该对象的详细定义,也就是在 MIB 中的定义,包括文字名称、所属 MIB、类型、状态、读写权限、描述信息,数字格式的 OID


-Tp

Print a graphical tree, rooted at the specified OID.

# 注释 :-Tp 用于打印从指定 OID 开始一直到该 OID 所属的 MIB 子树末端的树型结构信息

# 该选项很有用,如果要知道某个 MIB 或者某个表有什么内容,可以该选项


-Ta

Dump the loaded MIB in a trivial form.

# 注释 :-Ta 表示导出所有已经加载的 MIB 的数据,每个对象一行

# 默认情况下是导出所有已经加载的对象。

# 如果只想导出某个 MIB ,可以使用如 snmptranslate -Ta -M MTA-MIB 这样就只导出 MTA-MIB 下的信息

# 注释 :该选项其实和 -Tp 很像,只不过 -Tp 是树型结构的形式,而 -Ta 是一行一行的格式。

# 而且 -Tp 后面可以加 -m 或者某个 oid ,但 -Ta 后面加 <oid> 没有用


-Tl

Dump a labeled form of all objects.

# 注释 :-Tl 导出所有已经加载的 MIB 的对象,并且输出完整的 oid 路径,也是很有用的一个选项。

# 和 -Ta 相比,-Ta 只输出对象名,类型,值,而没有 OID 。而 -Tl 则除了这些外,还输出了完整的文字格式 OID 和 数字格式的 oid


-To

Dump a numeric form of all objects.

# 注释 :-To 则是导出已经加载的所有 MIB 的数字格式的 oid ,不含值和类型,仅仅有 oid 而已


-Ts

Dump a symbolic form of all objects.

# 注释 : -Ts 和 -To 相反,只输出文字格式的 OID 名称而已

# 以上两个选项,如果在只想知道某个 MIB 下有什么内容,而不关心具体的值时比较有用


-Tt

Dump a tree form of the loaded MIBs (mostly useful for debugging).

# 注释 :-Tt 和 -Tp 比较像,但相比 -Tp 来说不够清楚


-Tz

Dump a numeric and labeled form of all objects (compatible with MIB2SCHEMA format).

# 注释 ;-Tz 同时导出已经加载的 MIB 的所有对象的文字格式和数字格式的 OID

# 这也是一个比较有用的选项。


-V

Display version information for the application and then exit.

# 注释 :-V 选项显示版本信息并退出


-w WIDTH

Specifies the width of -Tp and -Td output. The default is very large.

# 注释 :-w 限制 -Tp 和 -Td 输出的最大宽度


In addition to the above options, snmptranslate takes the OID input (-I), MIB parsing (-M) and OID output (-O) options described in the INPUT OPTIONS, MIB PARSING OPTIONS and OUTPUT OPTIONS sections of the snmpcmd(1) manual page.

EXAMPLES

*

snmptranslate -On -IR sysDescr will translate "sysDescr" to a more qualified form:

system.sysDescr

# 注释 :如果要使 snmptranslate 把 symbol 格式的oid 转换为 numberic 格式的 oid ,需要使用 -IR 和 -On

# -IR 允许“随机”访问 MIB ,由 snmp 从 mib 库中查找和所给出的对象名匹配的 oid ,所以上面的例子可以直接写 sysDescr ,而不用写全路径

# 至于 -On 是输出数字格式的 oid ,这样就实现了把 symbol 格式的 oid 转换为 numberic 格式的 oid

*

snmptranslate -Onf -IR sysDescr will translate "sysDecr" to:

.iso.org.dod.internet.mgmt.mib-2.system.sysDescr

# 注释 :如果只是想找出 sysDescr 的 symbol 格式的 oid ,用 -Of

*

snmptranslate -Td -OS system.sysDescr will translate "sysDecr" into:

SNMPv2-MIB::sysDescr

sysDescr OBJECT-TYPE

-- FROM SNMPv2-MIB

-- TEXTUAL CONVENTION DisplayString

SYNTAX OCTET STRING (0..255)

DISPLAY-HINT "255a"

MAX-ACCESS read-only

STATUS current

DESCRIPTION "A textual description of the entity. This

value should include the full name and

version identification of the system's

hardware type, software operating-system,

and networking software."

::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) system(1) 1 }

*

snmptranslate -Tp -OS system will print the following tree:

+--system(1)

|

+-- -R-- String sysDescr(1)

| Textual Convention: DisplayString

| Size: 0..255

+-- -R-- ObjID sysObjectID(2)

+-- -R-- TimeTicks sysUpTime(3)

+-- -RW- String sysContact(4)

| Textual Convention: DisplayString

| Size: 0..255

+-- -RW- String sysName(5)

| Textual Convention: DisplayString

| Size: 0..255

+-- -RW- String sysLocation(6)

| Textual Convention: DisplayString

| Size: 0..255

+-- -R-- Integer sysServices(7)

+-- -R-- TimeTicks sysORLastChange(8)

| Textual Convention: TimeStamp

|

+--sysORTable(9)

|

+--sysOREntry(1)

|

+-- ---- Integer sysORIndex(1)

+-- -R-- ObjID sysORID(2)

+-- -R-- String sysORDescr(3)

| Textual Convention: DisplayString

| Size: 0..255

+-- -R-- TimeTicks sysORUpTime(4)

Textual Convention: TimeStamp

*

snmptranslate -Ta | head will produce the following dump:

dump DEFINITIONS ::= BEGIN

org ::= { iso 3 }

dod ::= { org 6 }

internet ::= { dod 1 }

directory ::= { internet 1 }

mgmt ::= { internet 2 }

experimental ::= { internet 3 }

private ::= { internet 4 }

security ::= { internet 5 }

snmpV2 ::= { internet 6 }

*

snmptranslate -Tl | head will produce the following dump:

.iso(1).org(3)

.iso(1).org(3).dod(6)

.iso(1).org(3).dod(6).internet(1)

.iso(1).org(3).dod(6).internet(1).directory(1)

.iso(1).org(3).dod(6).internet(1).mgmt(2)

.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1)

.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1)

.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1).sysDescr(1)

.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1).sysObjectID(2)

.iso(1).org(3).dod(6).internet(1).mgmt(2).mib-2(1).system(1).sysUpTime(3)

*

snmptranslate -To | head will produce the following dump

.1.3

.1.3.6

.1.3.6.1

.1.3.6.1.1

.1.3.6.1.2

.1.3.6.1.2.1

.1.3.6.1.2.1.1

.1.3.6.1.2.1.1.1

.1.3.6.1.2.1.1.2

.1.3.6.1.2.1.1.3

*

snmptranslate -Ts | head will produce the following dump

.iso.org

.iso.org.dod

.iso.org.dod.internet

.iso.org.dod.internet.directory

.iso.org.dod.internet.mgmt

.iso.org.dod.internet.mgmt.mib-2

.iso.org.dod.internet.mgmt.mib-2.system

.iso.org.dod.internet.mgmt.mib-2.system.sysDescr

.iso.org.dod.internet.mgmt.mib-2.system.sysObjectID

.iso.org.dod.internet.mgmt.mib-2.system.sysUpTime

*

snmptranslate -Tt | head will produce the following dump

org(3) type=0

dod(6) type=0

internet(1) type=0

directory(1) type=0

mgmt(2) type=0

mib-2(1) type=0

system(1) type=0

sysDescr(1) type=2 tc=4 hint=255a

sysObjectID(2) type=1

sysUpTime(3) type=8

NAME:snmpget

       

#注释:snmpget命令使用SNMP GET操作和网络实体进行通信的命令snmpget-使用SNMP GET请求与网络实体通信。从主机检索数据

内容

#注释:snmpget命令的格式是:snmpget [常用选项] [-Cf] oid [oid]

#也就是可以同时查询多个oid的值,例如:

[root @ dns1 root]#snmpget -IR localhost sysDescr.0 sysLocation.0

SNMPv2-MIB :: sysDescr.0 =字符串:Linux dns1.bob.com 2.4.20-31.9#1 Tue Apr 13 18:04:23 EDT 2004 i686

SNMPv2-MIB :: sysLocation.0 = STRING

[root @ dns1 root]#


描述

       snmpget是一个SNMP应用程序,它使用SNMP GET请求来查询

       有关网络实体的信息。一个或多个对象标识符

       (OID)可以作为命令行上的参数给出。每个变量

       名称均以variables(5)中指定的格式给出。

#注释:snmpget或snmpwalk,必须在命令行指定 . 的格式,不能只给出 object。

# 即使是 scalar 对象,例如 sysDescr ,sysLocation

       For example:

       snmpget -c public zeus system.sysDescr.0

       system.sysDescr.0 = "SunOS zeus.net.cmu.edu 4.1.3_U1 1 sun4m"

NAME:snmpwalk

SNMPWALK是一个通过SNMP GET-NEXT类型PDU,实现对目标AGENT的某指定MIB分支信息进行完整提取输出的命令工作。一次检索大量数据!

命令行:

snmpwalk [选项] agent [oid]

选项参数:

由于SNMP协议中,不同的协议版本存在不同的参数选项,以下参数按协议分开说明。

1.    普通选项

a) –h 显示帮助

b) –v 1|2c|3 指定SNMP协议版本

c) –V 显示当前SNMPWALK命令行版本

d) –r RETRIES 指定重试次数,默认为0次。

e) –t TIMEOUT 指定每次请求的等待超时时间,单为秒,默认为3秒。

f) –Cc 指定当在WALK时,如果发现OID负增长将是否继续WALK。

2. V1、V2C选项

a) –c COMMUNITY 指定共同体字符串

3. V3选项

a) –l LEVEL 指定安全级别:noAuthNoPriv|authNoPriv|authPriv

b) –u USER-NAME 安全名字

c) –a PROTOCOL 验证协议:MD5|SHA。如果-l指定为authNoPriv或authPriv时才需要。

d) –A PASSPHRASE 验证字符串。如果-l指定为authNoPriv或authPriv时才需要。

e) –x PROTOCOL 加密协议:DES。如果-l指定为authPriv时才需要。

f) –X PASSPHRASE 加密字符串:如果-l指定为authPriv时才需要

示例:

1.    SNMPWALK V1版本

snmpwalk –v 1 –c public 192.168.0.1 .1.3.6

使用v1版本,共同体为public,来对192.168.0.1的.1.3.6分支进行walk。

2.    SNMPWALK V2C版本

snmpwalk –v 2c –c cisco 192.168.0.2 .1

使用v2c版本,共同体为cisco,来对192.168.0.2的整个mib进行walk。

snmpwalk –v 2c –c cisco –Cc –r 1 –t 5 192.168.0.3 .1 > 192.168.0.3.mib

使用v2c版本,共同体为cisco,来对192.168.0.2的整个mib进行walk。并且通过-Cc指定OID负增长也可以继续,-r指定重试1次,-t指定超时为5秒,最后使用> 192.168.0.3.mib输出重定向到192.168.0.3.mib文件中去。

3.    SNMPWALK V3版本

snmpwalk –v 3 –l noAuthNoPriv –u gov 192.168.0.3 .1.3.6

使用v3版本,安全级别为noAuthNoPriv,指定安全名字为gov,对192.168.0.3设备的.1.3.6分支进行walk。

snmpwalk –v 3 –l authNoPriv –u gov –A MD5 –a “gov auth pass” –r 3 192.168.0.3 .1

使用v3版本,安全级别为authNoPriv,指定安全名字为gov,指定验证协议为MD5同时验证字符串为gov auth pass对192.168.0.3的整个mib进行walk。同时指定重试3次。

snmpwalk –v3 –l authPriv –u gov –A MD5 –a “gov auth pass” –X DES –x “gov priv pass” 192.168.0.3 .1.3.6

使用v3版本,安全级别为authNoPriv,指定安全名字为gov,指定验证协议为MD5同时验证字符串为gov auth pass,指定加密协议为DES同时验证字符串为gov priv pass,对192.168.0.3的.1.3.6分支mib进行walk。

实际使用说明:

1.    获取的目标与保存说明

针对研发需要的设备MIB资料进行调试的情况,一般需要设备的完整MIB,因此在进行设备的MIB获取时,使用使用.1作为目标mib分支(即完整mib文件)。并且一般需要将输出使用>重定向符,输出到一个指定的文件中,以方便传输。

2.    参数选项说明

一般都需要使用-Cc,来指定允许OID不重复。

如果设备较容易超时,需要使用-t与-r参数,来指定超时时间,与重试次数。

3.    正常WALK完整MIB文件说明

一般完整WALK到一个MIB,在MIB末尾,都会输出“End Of Mib”的字样。否则可能为Response timeout等错误,此时请根据错误消息及时调整参数。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SNMP(Simple Network Management Protocol)是一种网络管理协议,可以用于监控和管理网络设备。在命令行中使用SNMP,可以使用snmpget、snmpwalk、snmpset等命令。 1. snmpget命令用于获取一个或多个OID的值,语法如下: ``` snmpget [OPTIONS] AGENT OID [OID...] ``` 其中,AGENT是SNMP代理的IP地址或主机名,OID是要获取的对象标识符。例如,获取系统描述符可以使用以下命令: ``` snmpget -v 2c -c public localhost sysDescr.0 ``` 其中,-v 2c表示使用SNMP版本2c,-c public表示使用公共社区字符串,localhost表示SNMP代理的主机名,sysDescr.0表示系统描述符的OID。 2. snmpwalk命令用于遍历一个或多个OID的子树,语法如下: ``` snmpwalk [OPTIONS] AGENT OID [OID...] ``` 其中,AGENT和OID的含义与snmpget命令相同。例如,遍历系统信息可以使用以下命令: ``` snmpwalk -v 2c -c public localhost system ``` 其中,system表示系统信息的根OID。 3. snmpset命令用于设置一个或多个OID的值,语法如下: ``` snmpset [OPTIONS] AGENT OID TYPE VALUE [OID TYPE VALUE...] ``` 其中,AGENT和OID的含义与snmpget命令相同,TYPE表示要设置的值的类型,VALUE表示要设置的值。例如,设置系统联系人可以使用以下命令: ``` snmpset -v 2c -c private localhost sysContact.0 s "admin@example.com" ``` 其中,-c private表示使用私有社区字符串,sysContact.0表示系统联系人的OID,s表示字符串类型,"admin@example.com"表示要设置的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值