客戶端使用命令工具:snmpwalkhtml
服務端開啓服務 snmp service。下載安裝 net-snmp。python
最近作了一些工做,記性較差感受仍是記下來比較好,畢竟網上能查到的有用的資料太少了。工具
自定義OID (示例獲取文件內容)this
首先咱們須要找一個oid是否被系統佔用,好比.1.3.6.1.4.1.2021.5000編碼
# snmpwalk -v 2c -c public hostaddr .1.3.6.1.4.1.2021.5000 UCD-SNMP-MIB::ucdavis.5000 = No Such Object available on this agent at this OID
No Such Object available on this agent at this OID 表示該oid能夠使用;
服務端下載安裝net-snmp後,添加修改文件:spa
C:\usr\etc\snmp\snmpd.conf
文件內容示例:pwa
rocommunity public rwcommunity private extend .1.3.6.1.4.1.2021.5000 getinfofile C:/test/test.bat
其中第三行爲自定義OID信息;code
添加編輯文件 C:/test/test.bat (可自行修改)xml
文件內容示例:(中文路徑時,須要修改文件編碼)htm
@echo off
C:
type C:\test\系統信息.xml
所有文件添加完成後,在service.msc中重啓服務Net-snmp服務。(啓動net-snmp服務若是報錯 10064時,須要停用snmp service服務,而後啓動net-snmp)。
客戶端獲取命令:
snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.2021.5000(文件內容:test123456)
D:\python>snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.2021.5000 UCD-SNMP-MIB::ucdavis.5000.1.0 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.5000.2.1.2.10.103.101.116.119.105.110.105.110.102.111 = STRING: "C:/test/test.bat" UCD-SNMP-MIB::ucdavis.5000.2.1.3.10.103.101.116.119.105.110.105.110.102.111 = "" UCD-SNMP-MIB::ucdavis.5000.2.1.4.10.103.101.116.119.105.110.105.110.102.111 = "" UCD-SNMP-MIB::ucdavis.5000.2.1.5.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 5 UCD-SNMP-MIB::ucdavis.5000.2.1.6.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.5000.2.1.7.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.5000.2.1.20.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 4 UCD-SNMP-MIB::ucdavis.5000.2.1.21.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.5000.3.1.1.10.103.101.116.119.105.110.105.110.102.111 = STRING: "test123456" UCD-SNMP-MIB::ucdavis.5000.3.1.2.10.103.101.116.119.105.110.105.110.102.111 = STRING: "test123456" UCD-SNMP-MIB::ucdavis.5000.3.1.3.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.5000.3.1.4.10.103.101.116.119.105.110.105.110.102.111 = INTEGER: 0 UCD-SNMP-MIB::ucdavis.5000.4.1.2.10.103.101.116.119.105.110.105.110.102.111.1 = STRING: "test123456" D:\python>
服務端記錄完成,客戶端獲取到內容後須要解析到文件內容並保存文件,在下篇筆記中記錄。
使用python解析獲取文件內容筆記:https://www.cnblogs.com/dpf-10/p/9175471.html