snmp getTable demo :iftable ipAddresstable
package org.huangxf.snmp.test; import java.io.IOException;
import java.util.List; import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
import org.snmp4j.util.PDUFactory;
import org.snmp4j.util.TableEvent;
import org.snmp4j.util.TableUtils; public class ipTable {
public static void main(String[] args) {
ipTable.collectInterface();
} // 服务器接口集合
public static void collectInterface() {
TransportMapping transport = null;
Snmp snmp = null;
CommunityTarget target;
String[] IF_OIDS = { "1.3.6.1.2.1.2.2.1.1", // Index
"1.3.6.1.2.1.2.2.1.2", // descr
"1.3.6.1.2.1.2.2.1.3", // type
"1.3.6.1.2.1.2.2.1.5", // speed
"1.3.6.1.2.1.2.2.1.6", // mac
"1.3.6.1.2.1.2.2.1.7", // adminStatus
"1.3.6.1.2.1.2.2.1.8", // operStatus "1.3.6.1.2.1.2.2.1.10", // inOctets
"1.3.6.1.2.1.2.2.1.16", // outOctets
"1.3.6.1.2.1.2.2.1.14", // inError
"1.3.6.1.2.1.2.2.1.20", // outError
"1.3.6.1.2.1.2.2.1.13", // inDiscard
"1.3.6.1.2.1.2.2.1.19", // outDiscard
"1.3.6.1.2.1.2.2.1.11", // inUcastPkts
"1.3.6.1.2.1.2.2.1.17", // outUcastPkts
"1.3.6.1.2.1.2.2.1.12", // inNUcastPkts
"1.3.6.1.2.1.2.2.1.18" };// outNUcastPkts
String[] IP_OIDS = { "1.3.6.1.2.1.4.20.1.1", // ipAdEntAddr
"1.3.6.1.2.1.4.20.1.2", // ipAdEntIfIndex
"1.3.6.1.2.1.4.20.1.3" ,// ipAdEntNetMask
"1.3.6.1.2.1.4.20.1.4" ,//ipAdentBcastAddr
"1.3.6.1.2.1.4.20.1.5" };//ipAdEntReasmMaxSize
try {
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
snmp.listen();
target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setRetries();
target.setAddress(GenericAddress.parse("udp:127.0.0.1/161"));
target.setTimeout();
target.setVersion(SnmpConstants.version2c);
TableUtils tableUtils = new TableUtils(snmp, new PDUFactory() {
@Override
public PDU createPDU(Target arg0) {
PDU request = new PDU();
request.setType(PDU.GET);
return request;
}
});
OID[] columns = new OID[IF_OIDS.length];
for (int i = ; i < IF_OIDS.length; i++)
columns[i] = new OID(IF_OIDS[i]);
@SuppressWarnings("unchecked")
List<TableEvent> list = tableUtils.getTable(target, columns, null, null);
if (list.size() == && list.get().getColumns() == null) {
System.out.println(" null");
} else {
for (TableEvent event : list) {
VariableBinding[] values = event.getColumns();
if (values == null)
continue;
System.out.println("interface ---Index:" + values[].getVariable().toString() + " descr:"
+ " type:"
+ values[].getVariable().toString() + " speed:" + values[].getVariable().toString()
+ " mac:"
+ values[].getVariable().toString() + " operStatus:"
+ values[].getVariable().toString());
// System.out.println("interface ---Index:" + values[0].getVariable().toString() + " descr:"
// + getChinese(values[1].getVariable().toString()) + " type:"
// + values[2].getVariable().toString() + " speed:" + values[3].getVariable().toString()
// + " mac:" + getChinese(values[4].getVariable().toString()) + " adminStatus:"
// + values[5].getVariable().toString() + " operStatus:"
// + values[6].getVariable().toString());
}
}
// 获取ip
OID[] ipcolumns = new OID[IP_OIDS.length];
for (int i = ; i < IP_OIDS.length; i++)
ipcolumns[i] = new OID(IP_OIDS[i]);
@SuppressWarnings("unchecked")
List<TableEvent> iplist = tableUtils.getTable(target, ipcolumns, null, null);
if (iplist.size() == && iplist.get().getColumns() == null) {
System.out.println(" null");
} else {
for (TableEvent event : iplist) {
VariableBinding[] values = event.getColumns();
if (values == null)
continue;
System.out.println(" IP--->ipAdEntAddr:" + values[].getVariable().toString() + " ipAdEntIfIndex:"
+ values[].getVariable().toString() + " ipAdEntNetMask:"
+ values[].getVariable().toString() + " 3:" + values[].getVariable().toString()
+ " 4:"
+ values[].getVariable().toString() );
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (transport != null)
transport.close();
if (snmp != null)
snmp.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
snmp getTable demo :iftable ipAddresstable的更多相关文章
- JAVA8中Predicate,Consumer,UnaryOperator,Function接口的应用
笔者平时时间有限,直接贴代码,关于几个接口的差别,可以查看这两篇文章 感受lambda之美,推荐收藏,需要时查阅 https://juejin.im/post/5ce66801e51d455d850d ...
- SNMP
net-snmp 了解snmp程序最好的工具,snmpwalk和snmptable都是关键命令,举例: snmptable -v 2c -c public X.X.X.X ifTable 显示网络接口 ...
- SNMP 原理与实战详解
原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...
- SNMP OID列表 监控需要用到的OID
zabbix的snmp监控还没开始讲,不过先给大家列一些snmp常用的一些OID,比如cpu.内存.硬盘什么的.先了解这些,在使用snmp监控服务器. 系统参数(1.3.6.1.2.1.1) OID ...
- jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)
jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists) 贴出错误: java.lang.RuntimeExceptio ...
- Linux服务器SNMP常用OID (转)
原文地址:http://www.haiyun.me/archives/linux-snmp-oid.html 收集整理一些Linux下snmp常用的OID,用做服务器监控很不错. 服务器负载: 1 2 ...
- T4 代码生成 Demo (抽奖程序)
参考自这位大狮的: https://github.com/Pencroff/Dapper-DAL/blob/master/Dapper-DAL/Models/ModelGenerator.tt 项目 ...
- zabbix SNMP OID列表
系统参数(1.3.6.1.2.1.1) OID 描述 备注 请求方式 .1.3.6.1.2.1.1.1.0 获取系统基本信息 SysDesc GET .1.3.6.1.2.1.1.3.0 监控时间 s ...
- snmp模拟器snmpsid使用
snmpsim使用 安装 pip install snmpsim 简单使用 生成snmpwalk文件: snmpwalk -v2c -c 'password' -ObentU 218.200.x.15 ...
随机推荐
- Git and Xcode
1.web site "New Repository" 2.为本地 git 管理的项目添加 Repository $ cd ~/ProjectName$ git remote ad ...
- Apache的HBase与cdh的sqoop集成(不建议不同版本之间的集成)
1.修改sqoop的配资文件 2.从mysql导入到hbase(import) bin/sqoop import \ --connect jdbc:mysql://linux-hadoop3.ibei ...
- Struts Upload上传文件
1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...
- 修改delphi xe6 FMX Label字体颜色
delphi fmx的字体等设置默认与皮肤有关,用代码直接修改字体颜色等是无效的,如何才能用代码修改呢?请按以下方法就可以: 1.在Object inspector中取消StlyedSettings中 ...
- Ajax返回中文乱码问题(未解决)
(未解决) 暂时使用办法:改用返回Map<String,String>形式的返回值,在ajax中获取json形式的数据.
- readonly=“readonly”与readonly=“true”
<input id="u" readonly /> <input id="u" readonly="readonly" / ...
- GDB多线程调试
一.多线程调试1. 多线程调试,最重要的几个命令:info threads 查看当前进程的线程. ...
- 101个LINQ示例,包含几乎全部操作
Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...
- C# winForm程序开机启动和托盘显示 (转http://blog.csdn.net/xinyue3054/article/details/6599508)
这段时间一直进行cs项目,故整理下开机自动运行.托盘.显示.隐藏. (1).在窗口上点击关闭按钮或者最小化时将托盘显示: (2).双击托盘图标显示窗口: (3).右键点击托盘图标提供三个菜单选项,“退 ...
- js工具类大全
/********** 日期处理函数 *********/<script type="text/javascript" src="${springMacroRequ ...