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 ...
随机推荐
- Bootstrap 标签页和工具提示插件
一.标签页 标签页也就是通常所说的选项卡功能. //基本用法 <ul class="nav nav-tabs"> <li class="active&q ...
- lifecycle of opensource products--x86-64
x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为“IA ...
- json的eval为什么要用msg.d
在做一个关于搜索功能时用到了jquery autocomplete,发现返回数据时都用到了一个.d,比如: var datas = eval('(' + msg.d + ')'); 这个.d是什么呢, ...
- Linux 性能检测 - CentOS 安装 paramon
简介 paramon是一款性能检测工具. 数据发送:cnt 数据接收:svr Continue...
- java中String.valueOf()和toString()方法的区别
http://www.ztyhome.com/android-tostring-string-valueof-diff/
- JAVA中通过代码操作PC内容进行功能的实现
1.添加计划任务,用户项目中需要添加定时提醒功能: 计划任务只需要写一个继承java.util.TimerTask的类,覆盖其中的run方法即可,例如: import java.util.*; p ...
- Spring Boot 3 Hibernate
JdbcTemplate Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中. JdbcTemplate ...
- Glossary of view transformations
Glossary of view transformations The following terms are used to define view orientation, i.e. trans ...
- iOS SQLite 增删改查的封装(关系型)
在工程里导入libsqlite3.tbd库(Xcode 7) #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder &l ...
- LuaExpat笔记
xml xml是一种格式化数据交换语言, 适用于在网络上不同应用会话. http://www.xml.com/pub/a/98/10/guide0.html exPat 一种C语言实现的 xml 文档 ...