#!/usr/bin/env python3

################################################################################
# getFirmwareArubaOS.py
#
# gets oids from a list of switch ips, mostly used for firmware version
#
# ex.: ./getFirmwareArubaOS.py -c <community> -o <oid> -cf <path_to_cfg_file>
#
# oids_procurve:
# - firmware: 1.3.6.1.2.1.47.1.1.1.1.9.1
# - model: 1.3.6.1.2.1.47.1.1.1.1.2.1
# - hostname: 1.3.6.1.2.1.1.5.0
#
#
# to get it running,install necessary python libs:
# -
#
# Changes
# -2023-11-21: first version
#
################################################################################

import subprocess
import argparse

#########
# parser
#########
parser = argparse.ArgumentParser()
parser.add_argument("--debug", "-d", action="store_true")
parser.add_argument("--ip_address", "-ip", type=str)
parser.add_argument("--config_file", "-cf", type=str)

requiredArgs = parser.add_argument_group("required arguments")
requiredArgs.add_argument("--community", "-c", type=str, required=True)
requiredArgs.add_argument("--oid", "-o", type=str, required=True)
args = parser.parse_args()


if args.config_file:
config_file = open(args.config_file, "r")
ip_list = config_file.readlines()

for ip in ip_list:
ip = ip.rstrip()
try:
firmware_version = subprocess.check_output(f"snmpwalk -v 2c -c {args.community} {ip} {args.oid}", shell=True, stderr=subprocess.STDOUT)
firmware_version = firmware_version.decode("utf-8").split('"')[1]
except:
firmware_version = "unknown"
print(f"{ip}\t{firmware_version}")

else:
try:
firmware_version = subprocess.check_output(f"snmpwalk -v 2c -c {args.community} {args.ip_address} {args.oid}", shell=True, stderr=subprocess.STDOUT)
except:
firmware_version = "unknown"
print(f"{ip}\t{firmware_version}")

computer2know :: thank you for your visit :: have a nice day :: © 2024