window snmp服务开启及测试

转自:https://blog.csdn.net/qq_33314107/article/details/80031446

一 安装

二 开启服务

Linux下安装与配置snmp服务

https://blog.csdn.net/macrothunder/article/details/50394566

三 测试

3.1  MIB 浏览器测试

iReasoning MIB Browser下载地址:http://ireasoning.com/download.shtml

3.2  程序测试

maven导入依赖:

<!--snmp-->
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>2.5.0</version>
</dependency>

oid列表:

参照:https://blog.csdn.net/qq_28657577/article/details/82834442

public enum IndicatorOIDName {
//网络接口信息描述 网络接口类型 接口发送和接收的最大IP数据报[BYTE] 接口当前带宽[bps] 接口的物理地址 接口当前操作状态[up|down]
TEST("test", "测试", ".1.3.6.1.2.1.2.2.1.2," +
".1.3.6.1.2.1.2.2.1.3," +
".1.3.6.1.2.1.2.2.1.4," +
".1.3.6.1.2.1.2.2.1.5" +
".1.3.6.1.2.1.2.2.1.6," +
".1.3.6.1.2.1.2.2.1.8"), CPURATE("cpuRate", "总cpu占用率", "1.3.6.1.2.1.25.3.3.1.2"), //y
DISK_USE_RATE("diskUseRate", "磁盘使用率", "1.3.6.1.2.1.25.2.3.1.5,1.3.6.1.2.1.25.2.3.1.6"), //y ,前-总,后-已使用
//1:Physical memory ;3:Virtual memory; 6:Memory buffers;7:Cached memory
PHY_MEM_USE_PERCENT("phyMemUsePercent", "物理内存利用率","1.3.6.1.2.1.25.2.3.1.3," +
"1.3.6.1.2.1.25.2.3.1.5," +
"1.3.6.1.2.1.25.2.3.1.6"),
UP_STREAM("upStream", "上行流量监控(专用)", ".1.3.6.1.2.1.2.2.1.16"),
DOWN_STREAM("downStream", "下行流量监控(专用)", ".1.3.6.1.2.1.2.2.1.10"),
STREAM_SUM("streamSum", "上下行流量总和", ".1.3.6.1.2.1.2.2.1.10,.1.3.6.1.2.1.2.2.1.16"),
//网络接口信息描述 网络接口类型
NETWORK_INTERFACE("networkInterface", "网络接口", ".1.3.6.1.2.1.2.2.1.2,.1.3.6.1.2.1.2.2.1.3"); private String name;
private String mes;
private String oid; IndicatorOIDName(String name, String mes, String oid) {
this.name = name;
this.mes = mes;
this.oid = oid;
} public static IndicatorOIDName getByName(String name) {
for (IndicatorOIDName IndicatorOIDName : IndicatorOIDName.values()) {
if (name.startsWith(IndicatorOIDName.getName())) {
return IndicatorOIDName;
}
}
throw new RuntimeException("不支持类型 IndicatorOIDName.name=" + name);
} public String getName() {
return name;
} public String getMes() {
return mes;
} public String getOid() {
return oid;
}
}
Snmp4Uitl .java 测试类
public class Snmp4Uitl {
private static final Logger log = LoggerFactory.getLogger(Snmp4Uitl.class); public static void main(String[] args) throws IOException {
//ord aPublic 1.3.6.1.2.1.25.3.3.1.2 10.253.46.140 10.243.141.114
List<ChildIndicatorVo> indicatorVos= getChildIndicatorList("10.243.141.114",IndicatorOIDName.NETWORK_INTERFACE);
System.out.println(JSON.toJSONString(indicatorVos));
}
/***
* @Date: @Auth:xinsen.liao @Desc(V1.06): 获取磁盘内存指标
*/
public static List<ChildIndicatorVo> getChildIndicatorList(String ip,IndicatorOIDName indicatorOIDName) throws IOException { List<ChildIndicatorVo> indicatorVoList=new ArrayList<>();
List<TableEvent> aPublic = getTable(ip, indicatorOIDName.getOid().split(","), "public");
// System.out.println(JSON.toJSONString(aPublic));
for (TableEvent event : aPublic) {
OID oid = event.getIndex();
Integer index = oid.get(0);
VariableBinding[] valueBinds = event.getColumns();
Variable value = event.getColumns()[0].getVariable();
if(value!=null){
ChildIndicatorVo vo=new ChildIndicatorVo();
switch (indicatorOIDName.getName()){
case "cpuRate":
case "upStream":
case "downStream":
case "streamSum":
vo.setIndex(index);
vo.setOid(indicatorOIDName.getOid());
indicatorVoList.add(vo);
break;
case "networkInterface":
case "diskUseRate":
if(value.toString().toUpperCase().indexOf("MEMORY")>=0){
continue;
}
if(value!=null)
vo.setField(value.toString());
vo.setIndex(index);
vo.setOid(indicatorOIDName.getOid());
indicatorVoList.add(vo);
break;
}
}
}
return indicatorVoList;
}
public static PDU send(String ip, String oid, String community) throws IOException {
TransportMapping<UdpAddress> transportMapping = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transportMapping);
try {
snmp.listen();
ResponseEvent response = null;
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(oid)));
pdu.setType(PDU.GET);
String address = ip + "/" + 161;
Address targetAddress = new UdpAddress(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(community)); // 改字符串是我们在上面配置的
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(3000);
target.setVersion(SnmpConstants.version2c);
response = snmp.get(pdu, target);
PDU result = response.getResponse();
if (result == null) {
throw new RuntimeException("连接失败" + address + " community:" + community);
}
return result;
} catch (Exception ex) {
throw ex;
} finally {
snmp.close();
}
} public static List<TableEvent> getTable(String ip, String[] oids, String community) throws IOException {
TransportMapping transport = null;
Snmp snmp = null;
CommunityTarget target;
try {
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);//创建snmp
snmp.listen();//监听消息
target = new CommunityTarget();
target.setCommunity(new OctetString(community));
target.setRetries(2);
target.setAddress(GenericAddress.parse("udp:" + ip + "/161"));
target.setTimeout(8000);
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;
} @Override
public PDU createPDU(MessageProcessingModel messageProcessingModel) {
PDU request = new PDU();
request.setType(PDU.GET);
return request;
}
});
OID[] columns = new OID[oids.length];
for (int i = 0; i < oids.length; i++)
columns[i] = new OID(oids[i]);
List<TableEvent> list = tableUtils.getTable(target, columns, null, null);
return list;
} catch (Exception e) {
throw e;
} finally {
try {
if (transport != null)
transport.close();
if (snmp != null)
snmp.close();
} catch (IOException e) {
log.error("Snmp4Uitl[]getTable[]error", e);
}
}
}
}

windows下安装和配置SNMP的更多相关文章

  1. 网络基础 Windows下安装和配置net-snmp 代理

    Windows 下安装和配置net-snmp 代理[摘录] by:授客 QQ:1033553122   A.   安装  1.   安装前准备 ActivePerl-5.10.0.1004-MSWin ...

  2. PHP学习之-Mongodb在Windows下安装及配置

    Mongodb在Windows下安装及配置 1.下载 下载地址:http://www.mongodb.org/ 建议下载zip版本. 2.安装 下载windows版本安装就和普通的软件一样,直接下一步 ...

  3. windows下安装和配置redis

    1.windows下安装和配置redis 1.1 下载: 官网(linux下载地址):https://redis.io/ Windows系统下载地址:https://github.com/MSOpen ...

  4. windows下安装和配置多个版本的JDK

    https://jingyan.baidu.com/article/47a29f2474ba55c015239957.html 如何在windows下安装和配置多个版本的jdk,本文将带你在windo ...

  5. 基于svnserve的SVN服务器(windows下安装与配置)

    基于svnserve的SVN服务器(windows下安装与配置) 基于svnserve的SVN服务器(windows下安装与配置)关键字: svn 安装SVNserve 从http://subvers ...

  6. windows下安装和配置mongoDB

    上次在mac下安装和配置了mongodb,这次在windows下也尝试安装和配置mongodb. 1.首先下载mongodb压缩包,下载后解压到D盘或E盘.如下: 2.配置环境变量:桌面—计算机右键— ...

  7. windows下安装并配置mysql

    前言:前面三篇文章将django的环境搭建完后,还只能编写静态网页,如果要用到数据库编写动态网页,那么还需要数据库 本章讲解mysql5.6数据库的安装和配置,对于其他版本仅供参考,不一定试用!推荐使 ...

  8. 烂泥:Windows下安装与配置Nginx web服务器

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 前几篇文章,我们使用nginx都是在linux环境下,今天由于工作的需要.需要在windows环境也使用nginx搭建web服务器. 下面记录下有关ng ...

  9. windows下安装,配置gcc编译器

    在Windows下使用gcc编译器: 1.首先介绍下MinGW MinGW是指仅仅用自由软件来生成纯粹的Win32可运行文件的编译环境,它是Minimalist GNU on Windows的略称. ...

随机推荐

  1. [Luogu] 小凯的疑惑

    https://www.luogu.org/problemnew/show/P3951 考场上打表找规律的我写出了这样一份代码(紧张到爆<已经爆>) 当时一出考场听说是O(1)做法,当时就 ...

  2. Java 面试题 四

    1.序列化 File 类的介绍:http://www.cnblogs.com/ysocean/p/6851878.html Java IO 流的分类介绍:http://www.cnblogs.com/ ...

  3. 顺序表应用1:多余元素删除之移位算法(SDUT 3324)

    Problem Description 一个长度不超过10000数据的顺序表,可能存在着一些值相同的"多余"数据元素(类型为整型),编写一个程序将"多余"的数据 ...

  4. Python回归分析五部曲(三)—一元非线性回归

    (一)基础铺垫 一元非线性回归分析(Univariate Nonlinear Regression) 在回归分析中,只包括一个自变量和一个因变量,且二者的关系可用一条曲线近似表示,则称为一元非线性回归 ...

  5. 第三方库requests详解

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  6. Android学习_注意事项

    一. Fragment中加载ListView public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ...

  7. delete elasticsearch

    在elasticsearch-head 插件中遇到的删除特定的数据需求 DELETE /索引名/需要清空的type/_query { "query": { "match_ ...

  8. 7.RabbitMQ--消息确认机制(confirm)

    RabbitMQ--消息确认机制(confirm) Confirm模式 RabbitMQ为了解决生成者不知道消息是否真正到达broker这个问题,采用通过AMQP协议层面为我们提供了事务机制方案,但是 ...

  9. 简述JAVA类的生命周期

    介绍 一个java类的完整的生命周期会经历加载.连接.初始化.使用.和卸载五个阶段: 加载 主要是:把类的信息加载到方法区中,并在堆中实例化一个Class对象. 加载方式 根据类的全路径加载class ...

  10. .net 数据导出

    安装npoi,下面是具体的C#代码: public static XSSFWorkbook BuildWorkbook(DataTable dt) { var book = new XSSFWorkb ...