资源简介
java实现的简单网络管理协议!附件是整个工程,下载下来配置ip就可以运行,附有mib库,支持snmpV1,V2,V3版本协议!绝对是好资源,为了兼容移动的网络设备控制,研究了一段时间,现分享出来。不懂得可以找我
代码片段和文件信息
package com.cvicse.test.cs;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;
import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.StateReference;
import org.snmp4j.mp.StatusInformation;
import org.snmp4j.security.AuthMD5;
import org.snmp4j.security.PrivDES;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.security.USM;
import org.snmp4j.security.UsmUser;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
import com.cvicse.test.mib.MibDao;
/**
* 代理实现类
*
* @author Administrator
*
*/
public class SnmpAgent {
public static byte[] localEngineID;
private static SnmpAgent m_agent = null;
public static SnmpAgent getInstance() {
if (m_agent == null) {
m_agent = new SnmpAgent();
}
return m_agent;
}
public void setEngineId(byte[] id) {
localEngineID = id;
}
public byte[] getEngineId() {
return localEngineID;
}
public static class Handler implements CommandResponder {
protected java.lang.String mAddress = null;
protected int mPort = 0;
protected String mMyCommunityName = null;
protected TransportMapping mServerSocket = null;
protected Snmp mSNMP = null;
protected String value = null;
private byte[] localEngineID_pri;
public Handler() {
}
public void configure() {
mAddress = “192.168.11.2“;
mPort = 161;
mMyCommunityName = “OAagent“;
}
public void start(OctetString securityName OID authProtocol
OctetString authPass OID privacyProtocol
OctetString privacyPass) {
try {
mServerSocket = new DefaultUdpTransportMapping(new UdpAddress(
InetAddress.getByName(mAddress) mPort));
mSNMP = new Snmp(mServerSocket);
// 系统自动生成localEngineID
// localEngineID = MPv3.createLocalEngineID();
localEngineID = “测试程序“.getBytes();
USM usm = new USM(SecurityProtocols.getInstance()
new OctetString(localEngineID) 0);
SecurityModels.getInstance().addSecurityModel(usm);
mSNMP.setLocalEngine(localEngineID 0 0);
UsmUser user = new UsmUser(securityName authProtocol
authPass privacyProtocol privacyPass);
mSNMP.getUSM().addUser(securityName user);
mSNMP.addCommandResponder(this);
mServerSocket.listen();
} catch (UnknownHostException vException) {
System.out.println(vException);
} catch (IOException vException) {
System.out.println(vException);
}
}
@Override
public void processPdu(CommandResponderEvent aEvent) {
PDU command = aEvent.getPDU();
if (command != null) {
System.out.println(“success!“);
}
St
- 上一篇:java 客户关系管理系统
- 下一篇:动态代理cglibjar包和源码
相关资源
- Java编写的SNMP 客户端程序,可以通过
- 利用snmp协议获取机器设备信息 代码
- SNMP PDU报文解析JAVA实现
- SNMP测试工具 支持批量操作以及配置文
-
ob
jectSNMP开发组件zhtelecombasis.jar - zhtelecombasis.jar
- snmpforjava -demo最全
- AdventNet_Agent_Toolkit_Java_Edition_6_0_0
- 基于Java的SNMP网络管理系统
- SNMP管理站开发-java实现
- snmp4j完整
- 毕业答辩-JAVA基于SNMP网络设备MIB信息
- java通过SNMP协议获取交换机设备信息如
- JAVA基于SNMP网络设备MIB信息采集(论文
- snmp4j包来读取snmp协议数据
- Java基于SNMP/MIB的网络数据获取系统设
评论
共有 条评论