繁体   English   中英

如何在snmp4j中向MIB表添加行

[英]How to add rows to a MIB-table in snmp4j

我正在编写一个程序,该程序应该从本地路由器的白名单中读取和写入MAC地址。

我已经设法读取了这个所谓的“ wlanACLTable”的当前表内容,但是我无法使用SNMP向该表添加另一行。

我搜索了示例,但所有示例都是标量值。

我要联系的设备是路由器,来自Teldat的W2002

要添加行,您需要将数据写入表中的新行中。 要使用的OID是表OID +列+ IP + IfIndex(要配置的网络ID)+行

EG:1.3.6.1.4.1.272.4.46.8.1 +“ .1” +“ .255.255.255.255.255.255” +“ .200000” +“ .1337”

表:第1列:MAC(格式:6个数字0-255)第2列:IfIndex(整数第3列:状态行(启用1,禁用2,删除3))将其写入单个PDU,就像

pdu.addAll(new VariableBinding[]{new VariableBinding(new OID(Table_OID + ".1"+"."+stringMac +"."+IfIndex+"." + freeRow),mac),
                                 new VariableBinding(new OID(Table_OID + ".2"+"."+stringMac +"."+IfIndex+"." + freeRow),new Integer32(IfIndex)),
                                 new VariableBinding(new OID(Table_OID + ".3"+"."+stringMac +"."+IfIndex+"." + freeRow),new Integer32(1))});

最后,写入数据:使用低级别的Set请求(在本例中为SNMP V3)发送它们:

private Snmp snmp;

    public boolean executeSetRequest(String AccessName, String AccessPassword, ScopedPDU pdu) throws IOException {

            snmp.getUSM().addUser(new OctetString(AccessName), new UsmUser(new OctetString(AccessName), AuthMD5.ID, new OctetString(AccessPassword), PrivDES.ID, new OctetString(AccessPassword)));

            pdu.setType(ScopedPDU.SET);
            ResponseEvent response = snmp.send(pdu, getUserTarget(AccessName));

            if (response == null)
                throw new RuntimeException("SET timed out");

            return true;
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM