CiscoDevNet / python_code_samples_network

A collection of Python Code Samples for Network Management. Includes samples to run on-box and off-box.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retrieving device serial number from Cisco switch

Tiam-Abderezai opened this issue · comments

I want my script to 1) login to a Cisco switch and do a "show inventory" command (done successfully so far) 2) save the output of "SN: FOCxxxxxxxx" in memory instead of saving it to a local file.

I want to do this in order to be able to match each serial number to a particular IP address.

Any ideas what I can do to achieve this?

Thanks!
Tiam

I just added a script to this repo that does what you want with RESTCONF. You could use that as a model for CLI commands if you wanted. See the new RC-get-serial-numbers directory in this repo.

@xorrkaz Thank you!!!!!

I made a script that does that just in case anyone is interested. You can find it here.

Not all Cisco serial numbers will start with FOC. You might try this for your pattern:

regexoutput = re.search('SN:\s+(\w\d+)', output)
print(regexoutput.group(1))