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


Java TransportMapping.listen方法代码示例

本文整理汇总了Java中org.snmp4j.TransportMapping.listen方法的典型用法代码示例。如果您正苦于以下问题:Java TransportMapping.listen方法的具体用法?Java TransportMapping.listen怎么用?Java TransportMapping.listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.snmp4j.TransportMapping的用法示例。


在下文中一共展示了TransportMapping.listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not get any answers because the communication is asynchronous and the
 * listen() method listens for answers.
 * 
 * @throws IOException
 */

public void start() throws IOException {
	TransportMapping transport = new DefaultUdpTransportMapping();

	if (SNMPversion == 3) {
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
		SecurityModels.getInstance().addSecurityModel(usm);
	}
	snmp = new Snmp(transport);

	if (SNMPversion == 3)
		snmp.getUSM().addUser(new OctetString(ver3Username),
				new UsmUser(new OctetString(ver3Username), AuthMD5.ID, new OctetString(ver3AuthPasscode), null, null));

	// Do not forget this line!
	transport.listen();
}
 
开发者ID:dana-i2cat,项目名称:opennaas-routing-nfv,代码行数:24,代码来源:SNMPManager.java

示例2: createDevice

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
private void createDevice(String ipAddress, int port) throws IOException {
    Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
    TransportMapping transport = new DefaultUdpTransportMapping();
    transport.listen();
    snmp = new Snmp(transport);

    // setting up target
    target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(targetAddress);
    target.setRetries(3);
    target.setTimeout(1000 * 3);
    target.setVersion(SnmpConstants.version2c);
    target.setMaxSizeRequestPDU(MAX_SIZE_RESPONSE_PDU);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:LumentumSnmpDevice.java

示例3: start

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
public void start() throws IOException 
{
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	if("3".equals(this.version))//add v3 support
	{
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);  
		SecurityModels.getInstance().addSecurityModel(usm);  
	}
	// Do not forget this line!
	transport.listen();
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:19,代码来源:SNMPClient.java

示例4: start

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
/**
* Start the Snmp session. If you forget the listen() method you will not
* get any answers because the communication is asynchronous
* and the listen() method listens for answers.
* @throws IOException
*/
private void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
// Do not forget this line!
transport.listen();
}
 
开发者ID:rhamnett,项目名称:dazzl,代码行数:13,代码来源:SnmpTest.java

示例5: init

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
public void init() throws IOException {
	System.out.println("----> 初始 Trap 的IP和端口 <----");
	target = createTarget4Trap("udp:127.0.0.1/162");
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	transport.listen();
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:8,代码来源:SnmpTrapSendDemo.java

示例6: start

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
private void start() throws IOException {
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	// Do not forget this line!
	transport.listen();
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:13,代码来源:testSNMPQuery2.java

示例7: sendSnmpV1Trap

import org.snmp4j.TransportMapping; //导入方法依赖的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

示例8: sendTrapV1

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
public static void sendTrapV1(String port) throws IOException {

        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        transport.listen();

        CommunityTarget comtarget = new CommunityTarget();
        comtarget.setCommunity(new OctetString(new OctetString("public")));
        comtarget.setVersion(SnmpConstants.version1);
        comtarget.setAddress(new UdpAddress("127.0.0.1/" + port));
        comtarget.setRetries(2);
        comtarget.setTimeout(5000);

        PDU trap = new PDUv1();
        trap.setType(PDU.V1TRAP);

        OID oid = new OID("1.2.3.4.5");
        trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
        trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
        trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));

        // Add Payload
        Variable var = new OctetString("some string");
        trap.add(new VariableBinding(oid, var));

        // Send
        Snmp snmp = new Snmp(transport);
        snmp.send(trap, comtarget);
        transport.close();
        snmp.close();

    }
 
开发者ID:Stratio,项目名称:ingestion,代码行数:32,代码来源:SNMPUtils.java

示例9: sendTrapV3

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
public static void sendTrapV3(String port) {
    try {
        Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
                MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();

        snmp.getUSM().addUser(new OctetString("MD5DES"),
                new UsmUser(new OctetString("MD5DES"), null, null, null, null));

        // Create Target
        UserTarget target = new UserTarget();
        target.setAddress(targetAddress);
        target.setRetries(1);
        target.setTimeout(11500);
        target.setVersion(SnmpConstants.version3);
        target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
        target.setSecurityName(new OctetString("MD5DES"));

        // Create PDU for V3
        ScopedPDU pdu = new ScopedPDU();
        pdu.setType(ScopedPDU.NOTIFICATION);
        pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
        pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
        pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));

        // Send the PDU
        snmp.send(pdu, target);

        transport.close();
        snmp.close();
    } catch (Exception e) {
        System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
        System.err.println("Exception Message = " + e.getMessage());
    }
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:40,代码来源:SNMPUtils.java

示例10: createDevice

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
private void createDevice(String ipAddress, int port) throws IOException {
    Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
    TransportMapping transport = new DefaultUdpTransportMapping();
    transport.listen();
    snmp = new Snmp(transport);

    // setting up target
    target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(targetAddress);
    target.setRetries(3);
    target.setTimeout(1000L * 3L);
    target.setVersion(SnmpConstants.version2c);
    target.setMaxSizeRequestPDU(MAX_SIZE_RESPONSE_PDU);
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:16,代码来源:LumentumSnmpDevice.java

示例11: start

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
private void start() throws IOException {
    TransportMapping<? extends Address> transport = new DefaultUdpTransportMapping();
    snmp = new Snmp(transport);
    transport.listen();
}
 
开发者ID:globocom,项目名称:groot,代码行数:6,代码来源:SimpleSnmpClient.java

示例12: getIpOfGateway

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
public static String getIpOfGateway(){  
    String gatewayIpString=null; //网关ip地址是这个字符串的子串  
    String gatewayIp=null;  // 这是代表网关ip  
    try {  
         
        /** 
         * Set properties of target 
         */  
        CommunityTarget localhost = new CommunityTarget();  
        Address address = GenericAddress.parse("udp:127.0.0.1/161");  
        localhost.setAddress(address);  
        localhost.setCommunity(new OctetString("public"));    
        localhost.setRetries(2);   
        localhost.setTimeout(5*60);   
        localhost.setVersion(SnmpConstants.version2c);  
        /** 
         * Set protocols of UDP and SNMP 
         */  
        TransportMapping transport = new DefaultUdpTransportMapping();   
        transport.listen();  
        Snmp protocol = new Snmp(transport);  
        /** 
         * OID binding 
         */  
        PDU requestPDU = new PDU();  
        requestPDU.add(new VariableBinding(new OID("1.3.6.1.2.1.4.21.1.7")));//ipRouteNextHop  
        requestPDU.setType(PDU.GETNEXT);  
        /** 
         * 
         */  
        ResponseEvent responseEvent = protocol.send(requestPDU, localhost);  
        PDU responsePDU=responseEvent.getResponse();  
        if(responsePDU!=null){  
            VariableBinding getIp=responsePDU.get(0);  
            gatewayIpString=getIp.toString();  
        }  
    } catch (IOException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  
    gatewayIp=gatewayIpString.substring(31);  
    return gatewayIp;  
     
}
 
开发者ID:waylau,项目名称:snmp4j-demos,代码行数:45,代码来源:Snmp4jData.java

示例13: setUpTarget

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
/**
 * Helper method that initializes the snmp target to listening mode. This
 * method is explicitly for V3 messages. This method will create and set up
 * the TransportMapping and target for SNMP V3. It creates a
 * TransportMapping and puts it in the listening mode. Also Creates
 * CommunityTarget object and sets SNMP target properties.
 *
 * @param targetIP
 *            IP address of Target machine
 * @param portNumber
 *            Port number
 * @param userName
 *            The security name of the user
 * @param authenticatePassword
 *            The authentication password
 * @param privacyPassword
 *            The privacy password
 * @return The created UserTarget
 * @throws IOException
 *             IOException
 */
private UserTarget setUpTarget( final String targetIP, final int portNumber, final String userName,
        final String authenticatePassword, final String privacyPassword ) throws IOException
{

    // Creates a TransportMapping and puts the transport mapping in to
    // listen mode
    final TransportMapping transportMapping = new DefaultUdpTransportMapping();
    snmp = new Snmp( transportMapping );
    transportMapping.listen();

    // Creating a USM with the support for the supplied security protocols
    final SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
    securityProtocols.addDefaultProtocols();
    final OctetString engineId = new OctetString( MPv3.createLocalEngineID() );
    final USM usm = new USM( securityProtocols, engineId, DEFAULT_ENGINE_REBOOTS );
    SecurityModels.getInstance().addSecurityModel( usm );
    final OctetString username = new OctetString( userName );
    final OctetString authenticationPassphrase = new OctetString( authenticatePassword );
    final OctetString privacyPassphrase = new OctetString( privacyPassword );

    // Creating UsmUser and adds the UsmUser to the internal user name table
    // TODO Need to confirm, whether AuthMD5 and PrivDES needs to be changed
    final UsmUser usmuser = new UsmUser( username, AuthMD5.ID, authenticationPassphrase, PrivDES.ID,
            privacyPassphrase );
    snmp.getUSM().addUser( username, usmuser );

    // Create a target for a user based security model target and setting
    // its properties
    final UserTarget userTarget = new UserTarget();
    final InetAddress inetAddress = InetAddress.getByName( targetIP );
    final Address address = new UdpAddress( inetAddress, portNumber );
    userTarget.setAddress( address );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
    userTarget.setVersion( SnmpConstants.version3 );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setSecurityLevel( SecurityLevel.AUTH_PRIV );
    userTarget.setSecurityName( username );

    return userTarget;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:65,代码来源:SnmpManagerImpl.java

示例14: main

import org.snmp4j.TransportMapping; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
  System.out.println("SNMP GET-NEXT Simple Request");

  // Create TransportMapping and Listen
  TransportMapping transport = new DefaultUdpTransportMapping();
  transport.listen();

  // Create Target Address object
  CommunityTarget comtarget = new CommunityTarget();
  comtarget.setCommunity(new OctetString(community));
  comtarget.setVersion(snmpVersion);
  comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
  comtarget.setRetries(2);
  comtarget.setTimeout(1000);

  // Create the PDU object
  PDU pdu = new PDU();
  pdu.add(new VariableBinding(new OID(oidValue))); 
  pdu.setRequestID(new Integer32(1));
  pdu.setType(PDU.GETNEXT);
  
  // Create Snmp object for sending data to Agent
  Snmp snmp = new Snmp(transport);

  System.out.println("Sending GetNext Request to Agent ...");
  
  ResponseEvent response = snmp.getNext(pdu, comtarget);

  // Process Agent Response
  if (response != null)
  {
    System.out.println("\nResponse:\nGot GetNext Response from Agent...");
    PDU responsePDU = response.getResponse();

    if (responsePDU != null)
    {
      int errorStatus = responsePDU.getErrorStatus();
      int errorIndex = responsePDU.getErrorIndex();
      String errorStatusText = responsePDU.getErrorStatusText();

      if (errorStatus == PDU.noError)
      {
        System.out.println("Snmp GetNext Response for sysObjectID = " + responsePDU.getVariableBindings());
      }
      else
      {
        System.out.println("Error: Request Failed");
        System.out.println("Error Status = " + errorStatus);
        System.out.println("Error Index = " + errorIndex);
        System.out.println("Error Status Text = " + errorStatusText);
      }
    }
    else
    {
      System.out.println("Error: GetNextResponse PDU is null");
    }
  }
  else
  {
    System.out.println("Error: Agent Timeout... ");
  }
  snmp.close();
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:65,代码来源:testSNMPQuery.java

示例15: sendSnmpV2Trap

import org.snmp4j.TransportMapping; //导入方法依赖的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


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