You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10 IoT Core是否支持SNMP服务?寻求RaspberryPi3适用的C#方案

Windows 10 IoT Core on Raspberry Pi 3: SNMP Support & C# Implementation

嘿,刚好研究过这个问题,给你梳理清楚:

核心结论

Windows 10 IoT Core没有预装官方的SNMP服务——微软为了轻量化这个嵌入式系统,砍掉了桌面Windows里的SNMP组件。不过我们完全可以自己用C#实现一个轻量的SNMP代理,来支持基本的SNMP查询(比如像PC/服务器那样获取系统信息、接口数据)。

基于C#的SNMP代理实现步骤

我会用Lextm.SharpSnmpLib这个流行的SNMP库来实现,它对.NET Core(IoT Core支持.NET Core)很友好。

1. 准备工作

  • 在你的C#项目里安装NuGet包:Install-Package Lextm.SharpSnmpLib
  • 确保你的树莓派IoT Core设备已经开启了UDP 161端口的防火墙规则(SNMP默认监听端口)

2. 完整实现代码

using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using System;
using System.Net;

namespace IoT_SNMP_Agent
{
    class Program
    {
        static void Main(string[] args)
        {
            // 初始化SNMP代理,监听所有网卡的UDP 161端口
            var agent = new Agent(new IPEndPoint(IPAddress.Any, 161));
            
            // 注册常用SNMP OID的处理逻辑
            // 系统描述 (1.3.6.1.2.1.1.1.0)
            agent.RegisterHandler(ObjectIdentifier.Parse("1.3.6.1.2.1.1.1.0"), (sender, e) =>
            {
                e.ResponsePdu.VbList.Add(new VariableBinding(
                    ObjectIdentifier.Parse("1.3.6.1.2.1.1.1.0"),
                    new OctetString("Windows 10 IoT Core on Raspberry Pi 3")
                ));
            });
            
            // 系统名称 (1.3.6.1.2.1.1.5.0)
            agent.RegisterHandler(ObjectIdentifier.Parse("1.3.6.1.2.1.1.5.0"), (sender, e) =>
            {
                e.ResponsePdu.VbList.Add(new VariableBinding(
                    ObjectIdentifier.Parse("1.3.6.1.2.1.1.5.0"),
                    new OctetString("RaspberryPi-IoT")
                ));
            });
            
            // 系统运行时间 (1.3.6.1.2.1.1.3.0)
            var startTime = DateTime.UtcNow;
            agent.RegisterHandler(ObjectIdentifier.Parse("1.3.6.1.2.1.1.3.0"), (sender, e) =>
            {
                var uptime = DateTime.UtcNow - startTime;
                e.ResponsePdu.VbList.Add(new VariableBinding(
                    ObjectIdentifier.Parse("1.3.6.1.2.1.1.3.0"),
                    new TimeTicks((uint)uptime.TotalMilliseconds)
                ));
            });
            
            Console.WriteLine("SNMP Agent running on UDP port 161...");
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();
            
            agent.Stop();
        }
    }
}

3. 代码说明

  • 这个代理实现了SNMPv2c的基本GetRequest处理,支持三个最常用的系统OID
  • 你可以根据需求扩展更多OID的处理,比如接口信息(1.3.6.1.2.1.2分支)、CPU/内存使用率等
  • 部署时,要把项目编译成ARM架构(因为树莓派3是ARM处理器),然后通过Visual Studio部署到你的IoT Core设备

4. 测试方法

用任意SNMP工具(比如SNMP Walk、Paessler PRTG),输入树莓派的IP地址,SNMP版本选v2c,社区字符串用默认的public(代码里没做权限控制,你可以后续添加),就能查询到我们定义的系统信息了。

内容的提问来源于stack exchange,提问作者Dieter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:37:58