Created
May 15, 2019 04:30
-
-
Save masayoshi634/47aae0f806cab9f8711557728e5a4896 to your computer and use it in GitHub Desktop.
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 json | |
def get_snmp_static(): | |
""" /proc/net/snmp をparseして辞書形式を返す """ | |
with open('/proc/net/snmp', 'r') as fh: | |
protocols = [] | |
statics = [] | |
lines = fh.readlines() | |
for line in zip(*[iter(lines)] * 2): | |
keys = line[0].split() | |
values = line[1].split() | |
statics.append(dict(zip(keys[1:], [int(x) for x in values[1:]]))) | |
protocols.append(keys[0][:-1]) | |
return dict(zip(protocols, statics)) | |
if __name__ == "__main__": | |
print(json.dumps(get_snmp_static())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment