我正在编写一个应用程序来监视SNMP设备并将数据保存到SQL中。但是我遇到了时间上的问题。
大多数值都很容易作为浮动记录。原始的计时器号也很容易存储。但是,当我运行SNMPSharpNet时,(SnmpV1Packet)target.Request(pdu, param);返回一个值已解码的字符串:0d 4h 56m 0s 0ms
我想我可以解析这个值,但是将这个数字转换两次似乎是在浪费周期。如何获得毫秒的原始数?
发布于 2014-04-08 08:24:47
您试过将AsnType转换为SnmpSharpNet.TimeTicks吗?
UdpTarget target = new UdpTarget(IPAddress.Parse("192.168.1.1"));
Pdu pdu = new Pdu(PduType.Get);
pdu.VbList.Add("1.3.6.1.2.1.1.3.0");
AgentParameters param = new AgentParameters(SnmpVersion.Ver1, new OctetString("public"));
SnmpV1Packet packet = (SnmpV1Packet)target.Request(pdu, param);
AsnType uptimeAsn = packet.Pdu.VbList["1.3.6.1.2.1.1.3.0"].Value;
long uptime = ((TimeTicks)uptimeAsn).Milliseconds;
Console.WriteLine(uptime);
Console.WriteLine(new TimeSpan(0,0,(int)(uptime/1000)));只需确保将其包围在try/catch中,以防强制转换失败。
https://stackoverflow.com/questions/22850367
复制相似问题