简体   繁体   English

如何在snmp4j中向MIB表添加行

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

I am writing a program which is supposed to read and write MAC-addresses from and to the white-list of a local router. 我正在编写一个程序,该程序应该从本地路由器的白名单中读取和写入MAC地址。

I have managed to read the current table content of this so called "wlanACLTable", but I can't manage to add another row to this table using SNMP. 我已经设法读取了这个所谓的“ wlanACLTable”的当前表内容,但是我无法使用SNMP向该表添加另一行。

I searched for examples but all of them were for scalar values. 我搜索了示例,但所有示例都是标量值。

The device I want to contact is a router, a W2002 from Teldat 我要联系的设备是路由器,来自Teldat的W2002

To add a row, you need to write the data in a new row within the table. 要添加行,您需要将数据写入表中的新行中。 The OID to use is the Table OID+ the column + the IP + the IfIndex(the Network id you want to configure) + the row 要使用的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" EG:1.3.6.1.4.1.272.4.46.8.1 +“ .1” +“ .255.255.255.255.255.255” +“ .200000” +“ .1337”

Table: Column 1: MAC (format: 6 Numbers 0-255) Column 2: IfIndex (Integer Column 3: Status row(enabled 1, Disabled 2, delete 3) Write it to a single PDU just like 表:第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))});

Finally, to write the data: Send them with a low level Set request, in this case SNMP V3: 最后,写入数据:使用低级别的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