zoukankan      html  css  js  c++  java
  • Python Monitoring UPS with SNMPWALK

    ##Background

    My co-worker told me he needed to monitor UPS with SNMP module but he only can get hexadecimal digits from UPS module with SNMPWALK commands. Then I had to turn hexadecimal  to decimal. 
    He gave me a passage about IEEE754: http://www.softelectro.ru/ieee754_en.html
    C  12    F  15    
    B  11    E  14
    
    C2 05 FB EE 
    
    1100 0010 0000 0101 1111 1011 1110 1110
    
    1 = negative "-"
    
    1
    1000 01000
    0101 1111 1011 1110 1110
    
    1000 0100 = 132 - 127 = 5 so 2^5 = 32
    
    0000 1011 1111 0111 1101 110 = 392174, so 392174/2^23 = 0.0467507
    
    fomula = - 2^5 x (1+0.0467507) = -33.4 
    
    0101 1111 1011 1110 1110 = 392174
    
    C205FBEE

    Python Script

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    var = input("Please enter dec number:")
    b = bin(int(var, 16))
    print(b)
    S = int(b[2])
    #print(S)
    e = b[3:11]
    #print(e)
    
    E = int(e, 2)
    #print(E)
    
    m = b[12:]
    #print(m)
    M = int(m, 2)
    #print(M)
    
    F = ((-1)**S)*(2**(E-127))*(1+M/(2**23))
    print(round(F, 10))
    
    
  • 相关阅读:
    ajax post 时 form数据serialize()
    dapper 自定义数据库字段和代码中Model字段不一致时候的mapping方法
    TImage 的一些操作
    AOP
    SSL、数字签名、CA 工作原理
    RESTFUL
    tomcat
    Hibernate
    设计模式
    Spring配置
  • 原文地址:https://www.cnblogs.com/xilong-devops/p/10021226.html
Copyright © 2011-2022 走看看