File: get-serial.py

package info (click to toggle)
snimpy 0.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 484 kB
  • ctags: 435
  • sloc: python: 3,361; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/snimpy

"""
Get serial number of a given equipment using ENTITY-MIB
"""

from __future__ import print_function

import sys

load("ENTITY-MIB")

host=sys.argv[1]
s = M(host=host, community=sys.argv[2])

# Locate parent of all other elements
print("[-] %s: Search for parent element" % host)
parent = None
for i in s.entPhysicalContainedIn:
    if s.entPhysicalContainedIn[i] == 0:
        parent = i
        break
if parent is None:
    print("[!] %s: Unable to find parent" % host)
    sys.exit(1)
print("[+] %s: %s" % (host, s.entPhysicalDescr[parent]))
print("[+] %s: HW %s, FW %s, SW %s" % (host,
                                       s.entPhysicalHardwareRev[parent],
                                       s.entPhysicalFirmwareRev[parent],
                                       s.entPhysicalSoftwareRev[parent]))
print("[+] %s: SN %s" % (host,
                         s.entPhysicalSerialNum[parent]))