c 中的 snmpbulkwalk

发布于 2024-11-17 10:53:32 字数 2239 浏览 3 评论 0 原文

是否可以使用 netsnmp 在 C 中创建 snmpbulkwalk?

snmpget 非常简单 - 但我找不到发送 snmpbulkwalk 的示例...

这是 snmpget 的一个小示例:

    #include <net-snmp/net-snmp-config.h>
    #include <net-snmp/net-snmp-includes.h>
    #include <string.h>

    int snmp_get(struct snmp_session *sess_handle){
            struct snmp_pdu *pdu;
            struct snmp_pdu *response;
            struct variable_list *vars;

            oid id_oid[MAX_OID_LEN];
            oid serial_oid[MAX_OID_LEN];
            size_t id_len = MAX_OID_LEN;
            size_t serial_len = MAX_OID_LEN;
            int status;

            pdu = snmp_pdu_create(SNMP_MSG_GET);
            read_objid("SNMPv2-MIB::sysName.0", id_oid, &id_len);
            snmp_add_null_var(pdu, id_oid, id_len);
            read_objid(".1.3.6.1.2.1.1.3.0", serial_oid, &serial_len);
            snmp_add_null_var(pdu, serial_oid, serial_len);

            status = snmp_synch_response(sess_handle, pdu, &response);

            for(vars = response->variables; vars; vars = vars->next_variable)
                    print_value(vars->name, vars->name_length, vars);

            snmp_free_pdu(response);

            return status;


    }

    struct snmp_session *setup_snmp_session(int version, char* community, char* host){

                    struct snmp_session session;
                    struct snmp_session *sess_handle;

                    init_snmp("poller");
                    snmp_sess_init( &session );
                    session.version = version;
                    session.community = community;
                    session.community_len = strlen(session.community);
                    session.peername = host;
                    sess_handle = snmp_open(&session);
                    return sess_handle;

    }

    int main(int argc, char ** argv)
    {
            if(argv[1] == NULL){
            printf("Please supply a hostname\n");
            exit(1);
            }
struct snmp_session   *sess_handle=setup_snmp_session(SNMP_VERSION_2c,"asdf",argv[1]);
snmp_get(sess_handle);
snmp_close(sess_handle);

        return (0);
}

我正在寻找相同的东西 - 只是做 snmpbulkwalk! 谢谢你的帮助!

br, 罗埃吉

is it possible to create an snmpbulkwalk in C with netsnmp?

A snmpget is quite easy - but I cannot find an example to send an snmpbulkwalk...

Here is a little example for an snmpget:

    #include <net-snmp/net-snmp-config.h>
    #include <net-snmp/net-snmp-includes.h>
    #include <string.h>

    int snmp_get(struct snmp_session *sess_handle){
            struct snmp_pdu *pdu;
            struct snmp_pdu *response;
            struct variable_list *vars;

            oid id_oid[MAX_OID_LEN];
            oid serial_oid[MAX_OID_LEN];
            size_t id_len = MAX_OID_LEN;
            size_t serial_len = MAX_OID_LEN;
            int status;

            pdu = snmp_pdu_create(SNMP_MSG_GET);
            read_objid("SNMPv2-MIB::sysName.0", id_oid, &id_len);
            snmp_add_null_var(pdu, id_oid, id_len);
            read_objid(".1.3.6.1.2.1.1.3.0", serial_oid, &serial_len);
            snmp_add_null_var(pdu, serial_oid, serial_len);

            status = snmp_synch_response(sess_handle, pdu, &response);

            for(vars = response->variables; vars; vars = vars->next_variable)
                    print_value(vars->name, vars->name_length, vars);

            snmp_free_pdu(response);

            return status;


    }

    struct snmp_session *setup_snmp_session(int version, char* community, char* host){

                    struct snmp_session session;
                    struct snmp_session *sess_handle;

                    init_snmp("poller");
                    snmp_sess_init( &session );
                    session.version = version;
                    session.community = community;
                    session.community_len = strlen(session.community);
                    session.peername = host;
                    sess_handle = snmp_open(&session);
                    return sess_handle;

    }

    int main(int argc, char ** argv)
    {
            if(argv[1] == NULL){
            printf("Please supply a hostname\n");
            exit(1);
            }
struct snmp_session   *sess_handle=setup_snmp_session(SNMP_VERSION_2c,"asdf",argv[1]);
snmp_get(sess_handle);
snmp_close(sess_handle);

        return (0);
}

I am looking for something equal - just doing an snmpbulkwalk!
Thx for your help!

br,
roegi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-11-24 10:53:32

您是否知道已经有 snmpbulkwalk 命令行实现是一个很好的例子吗?它已经做你想要的了。如果您想要 GETBULK 的单个实例,那么您可以查看更简单的 snmpbulkget 示例代替。

Are you aware that there is already a snmpbulkwalk command line implementation within Net-SNMP that would be a good example to look at? It does what you want already. If you want a single instance of a GETBULK, then you could look at the simpler snmpbulkget example instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文