一、简介

snmp-cmds模块通过SNMP与目标设备进行通信,此模块适用于windows,此模块是基于系统已安装了net-snmp环境
easysnmp模块通过SNMP与谬表设备进行通信,此模块用于linux,此模块基于系统已安装了net-snmp环境

二、snmp-cmds模块安装

  2.1 在Windows平台

#1.系统环境安装net-snmp软件
a.下载链接: https://pan.baidu.com/s/1sq4mjIMfFgG2YxTMLxVF0A 提取码: a7j5
b.安装完成,打开cmd命令框,输入snmpwalk,无报错,有回显,即安装正常 #2.使用pip工具安装snmp-cmds模块
pip3 install snmp-cmds

  2.2 在Centos 7平台

#1.系统环境安装net-snmp软件
a.yum install python-devel
b.安装setuptools
wget https://files.pythonhosted.org/packages/25/5d/cc55d39ac39383dd6e04ae80501b9af3cc455be64740ad68a4e12ec81b00/setuptools-0.6c11-py2.7.egg
c.安装net-snmp-5.7.3软件
wget https://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.3/net-snmp-5.7.3.tar.gz
d.提升setuptools为可执行文件
chmod +x setuptools-0.6c11-py2.7.egg
e. ./setuptools-0.6c11-py2.7.egg
f. tar -zxvf net-snmp-5.7.3.tar.gz
g. cd net-snmp-5.7.3
h. ./configure --with-python-modules #选择版本时,输入2,其余直接回车
i. make (时间较长)
j. make install
k. echo "/usr/local/lib" >> /etc/ld.so.conf
l. ldconfig
m. 验证,是否有snmpwalk命令 #2.使用pip工具安装snmp-cmds模块
pip3 install easysnmp ps:easysnmp官方文档地址:https://easysnmp.readthedocs.io/en/latest/

三、简单实例

  3.1 获取目标设备的接口名字

from snmp_cmds import snmpwalk
#返回结果是列表
res = snmpwalk(ipaddress='192.168.59.251',oid='IF-MIB:ifDescr',community='qiji123') for line in res:
#第一个元素为oid,第二个元素为接口名字
print(line[0],' ',line[1])

  3.2 使用pysnmp模块案例

from easysnmp import snmp_walk

device_ip = 'IP地址'
community = '团体字'
# oid = 'IF-MIB::ifDescr'
oid = 'sysDescr' def test():
res = snmp_walk(oid, hostname=device_ip, community=community, version=2) for each in res:
print(each.value) if __name__ == '__main__':
test()

最新文章

  1. Linux系统资源查看
  2. 一个python线程池的源码解析
  3. 自定义表并实现Identity登录(一)
  4. C#中 导入和导出Excel的方法
  5. 关于js的兼容问题(小办法)!
  6. Servlet能读到JSessionID,读不到其它cookie问题
  7. HDU 2554 N对数的排列问题
  8. html 中 #include file 的用法
  9. 我用爬虫一天时间“偷了”知乎一百万用户,只为证明PHP是世界上最好的语言
  10. JS面向对象基础2
  11. android调用系统相机
  12. jquery 表格行计算
  13. int-整数+bool-布尔功能介绍
  14. Human Interface Device (HID) Class Decoder
  15. 在一台服务器上搭建多个项目的SVN
  16. 原创BULLET物理的DEMO
  17. myeclipse 复制项目不包含svn或CVS目录
  18. Vue 从零开始--搭建环境
  19. RDP 协议组件 X.224 在协议流中发现一个错误并且中断了客户端连接
  20. 工作流-----WorkFlow

热门文章

  1. Web前端三大框架_vue源码笔记
  2. 哈夫曼编码与解码的C++实现:建立哈夫曼树、进行哈夫曼编码与解码
  3. Lucene05-分词器
  4. 洛谷 P1039 侦探推理
  5. 嵌入式web服务器BOA的移植及应用
  6. [POJ 2888]Magic Bracelet[Polya Burnside 置换 矩阵]
  7. 为什么选择 Spring 作为 Java 框架
  8. fjnuoj 1003 学长的QQ号
  9. FJNUOJ 1002 画葫芦。。
  10. 浅谈hosts文件