File: get-serial.py

package info (click to toggle)
snimpy 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 620 kB
  • sloc: python: 4,191; makefile: 209
file content (30 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/snimpy

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

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("[+] {}: {}".format(host, s.entPhysicalDescr[parent]))
print("[+] {}: HW {}, FW {}, SW {}".format(host,
                                           s.entPhysicalHardwareRev[parent],
                                           s.entPhysicalFirmwareRev[parent],
                                           s.entPhysicalSoftwareRev[parent]))
print("[+] {}: SN {}".format(host,
                             s.entPhysicalSerialNum[parent]))