Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用oid通过Snmp4J java客户端设置ipv6地址?_Java_Snmp_Snmp4j - Fatal编程技术网

如何使用oid通过Snmp4J java客户端设置ipv6地址?

如何使用oid通过Snmp4J java客户端设置ipv6地址?,java,snmp,snmp4j,Java,Snmp,Snmp4j,如何使用snmp4j和java客户端设置Ipv6 IP地址?我可以使用snmp4j设置ipv4 IP地址。下面是使用snmp4j设置ipv4 IP地址的代码快照。我对ipv6使用相同的方法,但没有给出正确的结果。如果我正在传递ipv6地址,即“20xx:04xx:00xx:40xx:0000:XXXX:00xx”。然后,正在设置的值为xx.xx.xx.xx.00.xx.xx。它只是从每个八位组中删除前两个数字。就像从20xx开始,它删除了20个,并且以同样的方式为所有人删除 PDU pdu =

如何使用snmp4j和java客户端设置Ipv6 IP地址?我可以使用snmp4j设置ipv4 IP地址。下面是使用snmp4j设置ipv4 IP地址的代码快照。我对ipv6使用相同的方法,但没有给出正确的结果。如果我正在传递ipv6地址,即“20xx:04xx:00xx:40xx:0000:XXXX:00xx”。然后,正在设置的值为xx.xx.xx.xx.00.xx.xx。它只是从每个八位组中删除前两个数字。就像从20xx开始,它删除了20个,并且以同样的方式为所有人删除

PDU pdu = SnmpSession.getPDU(OID_TO_SET_TFTPSERVER_IPADDRESS, "oa:be:09:ef"); //ipv4 address 
enter code here in hexa decimal format
SnmpSession.sendWrite(pdu, target);

public static PDU getPDU(String str , Object value ) {
    OID oid = new OID(str);
    final PDU pdu = new PDU();
    pdu.setType(PDU.SET);
    Variable var = null;
    try {
        var = SnmpTypeConverter.mapHexStringToVariable(value);
        
    } catch (Exception e) {
        logger.info(e.getMessage(), e);
    }
    pdu.add(new VariableBinding(oid, var));
    return pdu;
    
}

public static Variable mapHexStringToVariable(Object value) {
    String str = (String)value;
    Variable vb =  OctetString.fromHexString( str);
    return vb;
}

public static boolean sendWrite(final PDU pdu, Target mWriteTarget) throws InterruptedException, SnmpException {
    boolean isSetUP = true;
    try {
        Snmp mSnmp = new Snmp(new DefaultUdpTransportMapping());
        mSnmp.listen();
        final ResponseEvent responseEvt = mSnmp.send(pdu, mWriteTarget);
        if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedException("SNMP write interupted");
        }

        final PDU response = responseEvt.getResponse();
        
        if (response != null) {
            if (response.getErrorStatus() != SnmpConstants.SNMP_ERROR_SUCCESS) {
                isSetUP = false;
            logger.info("Agent error code: " + response.getErrorStatus() + " - "
                    + response.getErrorStatusText() + " - " + response.getVariableBindings().toString());
            throw new SnmpException("Agent error code: "
                    + response.getErrorStatus() + " - "
                    + response.getErrorStatusText() + " - "
                    + response.getVariableBindings().toString());
        }

        if (response.getType() == PDU.REPORT) {
            final VariableBinding bind = response.get(0);
                logger.info("Report recieved: " + bind.toString());
        }
        return isSetUP;
    }
    } catch (final IOException ex) {
        logger.info(ex.getMessage(), ex);
        logger.info("Error While setting the value");
    }
    return isSetUP;
}