title: Create SNMP Client in JAVA Using SNMP4j for ipv6 addresses
body: <p>I am trying to create an SNMP client in JAVA. </p>
  
  <pre><code>SNMPManager client = new SNMPManager("udp:73.251.102.191/162");
  </code></pre>
  
  <p>This is good for an ipv4 address, but when I am trying to do the same with ipv6 addresses it throws the below error.</p>
  
  <p>Error:</p>
  
  <pre><code>---------------Exception in thread "main" org.snmp4j.MessageException: No route to host
  at org.snmp4j.MessageDispatcherImpl.sendPdu(Unknown Source)
  at org.snmp4j.Snmp.sendMessage(Unknown Source)
  at org.snmp4j.Snmp.send(Unknown Source)
  at org.snmp4j.Snmp.send(Unknown Source)
  at snmpTrial1.SNMPManager.get(SNMPManager.java:55)
  at snmpTrial1.SNMPManager.getAsString(SNMPManager.java:45)
  at snmpTrial1.SNMPManager.main(SNMPManager.java:34)
  </code></pre>
  
  <p>Code: This code works for ipv4 addresses but not ipv6</p>
  
  <pre><code>public class SNMPManager {
  Snmp snmp = null;
  String address = null;
  public SNMPManager(String add)
  {
      address = add;
  }
  public static void main(String[] args) throws IOException {
      SNMPManager client = new SNMPManager("udp:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/162"); // ipv6 address
      client.start();
      String sysDescr = client.getAsString(new OID(".1.3.6.1.4.1.4115.1.20.1.1.3.62.4.1.1.1"));
      System.out.println(sysDescr);
  }
  private void start() throws IOException {
      TransportMapping transport = new DefaultUdpTransportMapping();
      snmp = new Snmp(transport);
      transport.listen();
  }
  
  public String getAsString(OID oid) throws IOException {
      ResponseEvent event = get(new OID[] { oid });
      return event.getResponse().get(0).getVariable().toString();
  }
  public ResponseEvent get(OID oids[]) throws IOException {
      PDU pdu = new PDU();
      for (OID oid : oids) {
          pdu.add(new VariableBinding(oid));
      }
      pdu.setType(PDU.GET);
      ResponseEvent event = snmp.send(pdu, getTarget(), null);
      if(event != null) {
          return event;
      }
      throw new RuntimeException("GET timed out");
  }
  private Target getTarget() {
      Address targetAddress = GenericAddress.parse(address);
      CommunityTarget target = new CommunityTarget();
      target.setCommunity(new OctetString("xxxxx"));
      target.setAddress(targetAddress);
      target.setRetries(2);
      target.setTimeout(2000);
      target.setVersion(SnmpConstants.version2c);
      return target;
  }
  </code></pre>
  
  <p>}</p>