Last active
June 21, 2021 12:02
-
-
Save jsenin/33e3cbcbeae5eccb6933884f28344786 to your computer and use it in GitHub Desktop.
pack and unpack octects from snmp oids in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import datetime | |
ts = 1620386580.0 | |
dt = datetime.datetime.fromtimestamp(ts) | |
packed = struct.pack(">hbbbbbb", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond) | |
print ("packed", packed, ts ) | |
tp = dt.timetuple() # expand values in a tuple | |
import time | |
unpacked = struct.unpack('>hbbbbbb', packed) | |
dt = datetime.datetime(*unpacked) | |
ts = time.mktime(dt.timetuple()) + (dt.microsecond / 1000000.0) | |
1620386580.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example from a huawei OLT response
How to 'decrypt' the date time values