本文整理汇总了Java中org.snmp4j.smi.IpAddress类的典型用法代码示例。如果您正苦于以下问题:Java IpAddress类的具体用法?Java IpAddress怎么用?Java IpAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IpAddress类属于org.snmp4j.smi包,在下文中一共展示了IpAddress类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTest
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public void sendTest(String agentAddress, int port, String community, PDU pdu) {
for (RegistrationInfo info : s_registrations.values()) {
if (port == info.getPort()) {
Snmp snmp = info.getSession();
MessageDispatcher dispatcher = snmp.getMessageDispatcher();
TransportMapping transport = info.getTransportMapping();
int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel,
securityModel, community.getBytes(),
SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);
info.getHandler().processPdu(e);
}
}
}
示例2: toObject
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
private static Object toObject(Variable variable) {
if (variable instanceof OID) {
return ((OID) variable).toIntArray();
}
else if (variable instanceof OctetString) {
return ((OctetString) variable).toByteArray();
}
else if (variable instanceof IpAddress) {
return ((IpAddress) variable).toByteArray();
}
else {
return variable.toLong();
}
}
示例3: sendSnmpV1Trap
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
/**
* This methods sends the V1 trap to the Localhost in port 163
*/
public void sendSnmpV1Trap()
{
try
{
//Create Transport Mapping
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
//Create Target
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
comtarget.setRetries(2);
comtarget.setTimeout(5000);
//Create PDU for V1
PDUv1 pdu = new PDUv1();
pdu.setType(PDU.V1TRAP);
pdu.setEnterprise(new OID(trapOid));
pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
pdu.setSpecificTrap(1);
pdu.setAgentAddress(new IpAddress(ipAddress));
//Send the PDU
Snmp snmp = new Snmp(transport);
System.out.println("Sending V1 Trap to " + ipAddress + " on Port " + port);
snmp.send(pdu, comtarget);
snmp.close();
}
catch (Exception e)
{
System.err.println("Error in Sending V1 Trap to " + ipAddress + " on Port " + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例4: processPdu
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
@Override
public void processPdu(CommandResponderEvent e) {
PDU command = new PDU(e.getPDU());
IpAddress addr = ((IpAddress)e.getPeerAddress());
if (command != null) {
if (command.getType() == PDU.INFORM) {
PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
e.getSecurityModel(),
e.getSecurityName(),
e.getSecurityLevel(),
response,
e.getMaxSizeResponsePDU(),
ref,
statusInformation);
if (log().isDebugEnabled()) {
log().debug("Sent RESPONSE PDU to peer " + addr + " acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
} catch (MessageException ex) {
log().error("Error while sending RESPONSE PDU to peer " + addr + ": " + ex.getMessage() + "acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
}
}
if (e.getPDU() instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1)e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
}
}
示例5: toInetAddress
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public InetAddress toInetAddress() {
switch (m_value.getSyntax()) {
case SMIConstants.SYNTAX_IPADDRESS:
return ((IpAddress)m_value).getInetAddress();
default:
throw new IllegalArgumentException("cannot convert "+m_value+" to an InetAddress");
}
}
示例6: generateRowData
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
private static Variable[] generateRowData(List<MyMibNode> columnNodes) {
Variable[] rowValues = new Variable[columnNodes.size()];
for (int i = 0; i < columnNodes.size(); i++) {
MyMibNode columnNode = columnNodes.get(i);
String rule = columnNode.getRule();
if("Counter32".equals(columnNode.getType())){
rowValues[i] = new Counter32(Long.parseLong("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("Gauge32".equals(columnNode.getType())){
rowValues[i] = new Gauge32(Long.parseLong("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("Integer32".equals(columnNode.getType()) || "INTEGER".equals(columnNode.getType())){
rowValues[i] = new Integer32(Integer.parseInt("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("TimeTicks".equals(columnNode.getType())){
rowValues[i] = new TimeTicks();
}
if("Unsigned32".equals(columnNode.getType())){
rowValues[i] = new Integer32(Integer.parseInt("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomInt(1, 512)}") : TestDataUtil.parseInnerMethod(rule)));
}
if("IpAddress".equals(columnNode.getType())){
rowValues[i] = new IpAddress("10.10.10.10");
}
if("OCTET STRING".equals(columnNode.getType())){
rowValues[i] = new OctetString("".equals(rule) ? TestDataUtil.parseInnerMethod("${randomString(5)}") : TestDataUtil.parseInnerMethod(rule));
}
}
return rowValues;
}
示例7: processPdu
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public void processPdu(CommandResponderEvent e) {
PDU command = new PDU(e.getPDU());
IpAddress addr = ((IpAddress)e.getPeerAddress());
if (command != null) {
if (command.getType() == PDU.INFORM) {
PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
e.getSecurityModel(),
e.getSecurityName(),
e.getSecurityLevel(),
response,
e.getMaxSizeResponsePDU(),
ref,
statusInformation);
if (log().isDebugEnabled()) {
log().debug("Sent RESPONSE PDU to peer " + addr + " acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
} catch (MessageException ex) {
log().error("Error while sending RESPONSE PDU to peer " + addr + ": " + ex.getMessage() + "acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
}
}
if (e.getPDU() instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1)e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
}
}
示例8: sendSnmpV2Trap
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
/**
* This methods sends the V2 trap to the Localhost in port 163
*/
public void sendSnmpV2Trap()
{
try
{
//Create Transport Mapping
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
//Create Target
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setVersion(SnmpConstants.version2c);
comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
comtarget.setRetries(2);
comtarget.setTimeout(5000);
//Create PDU for V2
PDU pdu = new PDU();
// need to specify the system up time
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(new Date().toString())));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trapOid)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(ipAddress)));
// variable binding for Enterprise Specific objects, Severity (should be defined in MIB file)
pdu.add(new VariableBinding(new OID(trapOid), new OctetString("Major")));
pdu.setType(PDU.NOTIFICATION);
//Send the PDU
Snmp snmp = new Snmp(transport);
System.out.println("Sending V2 Trap to " + ipAddress + " on Port " + port);
snmp.send(pdu, comtarget);
snmp.close();
}
catch (Exception e)
{
System.err.println("Error in Sending V2 Trap to " + ipAddress + " on Port " + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
示例9: setAgentAddress
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public void setAgentAddress(InetAddress agentAddress) {
getPDUv1().setAgentAddress(new IpAddress(agentAddress));
}
示例10: getIpAddress
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public SnmpValue getIpAddress(InetAddress val) {
return new Snmp4JValue(new IpAddress(val));
}
示例11: getOspfIfMetricEntryOID
import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
/**
* Get the corresponding OID of the ospfIfMetricTable for the passed indexes
*
* @param entryOid
* ospfIfMetricEntry OID
* @param ipAddress
* ospfIfMetricIpAddress
* @param addressLessIf
* ospfIfMetricAddressLessIf
* @param ifMetricTos
* ospfIfMetricTOS
* @return The ospfIfMetricEntry OID completed with the indexes
*/
public static final OID getOspfIfMetricEntryOID(OID entryOid,
InetAddress ipAddress, int addressLessIf, int ifMetricTos) {
IpAddress addr = new IpAddress(ipAddress);
Integer32 lessIf = new Integer32(addressLessIf);
Integer32 tos = new Integer32(ifMetricTos);
return new OID(entryOid).append(addr.toSubIndex(false))
.append(lessIf.toSubIndex(false)).append(tos.toSubIndex(false));
}