当前位置: 首页>>代码示例>>Java>>正文


Java IpAddress类代码示例

本文整理汇总了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);
        }
    }

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:Snmp4JStrategy.java

示例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();
  }
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:15,代码来源:Snmp4jVarbind.java

示例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());
  }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:40,代码来源:sendSNMPTrap.java

示例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()));
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:Snmp4JTrapNotifier.java

示例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"); 
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:9,代码来源:Snmp4JValue.java

示例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;
}
 
开发者ID:wangzijian777,项目名称:snmpTool,代码行数:37,代码来源:MOTableGenerator.java

示例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()));
    }
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:37,代码来源:Snmp4JTrapNotifier.java

示例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());
  }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:44,代码来源:sendSNMPTrap.java

示例9: setAgentAddress

import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public void setAgentAddress(InetAddress agentAddress) {
    getPDUv1().setAgentAddress(new IpAddress(agentAddress));
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:4,代码来源:Snmp4JV1TrapBuilder.java

示例10: getIpAddress

import org.snmp4j.smi.IpAddress; //导入依赖的package包/类
public SnmpValue getIpAddress(InetAddress val) {
    return new Snmp4JValue(new IpAddress(val));
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:4,代码来源:Snmp4JValueFactory.java

示例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));

}
 
开发者ID:ccascone,项目名称:JNetMan,代码行数:24,代码来源:MIB.java


注:本文中的org.snmp4j.smi.IpAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。