0

I am doing TDR cable-diagnostics on a Cisco switch and I need to know how to transfer that information to Excel (ordered).

from netmiko import ConnectHandler

#Credenciales
ip = "192.168.xx.xx"
username = "admin"
password = "pass"
pass_enable = "secret"
DEVICE_TYPE = 'cisco_ios'

conexion = ConnectHandler(ip=ip, username=username, password=password, secret=pass_enable, device_type=DEVICE_TYPE)

if not conexion.check_enable_mode():
    conexion.enable()

tdr = conexion.send_command('show cable-diagnostics tdr interface Gi1/0/1', use_textfsm=True)

print(tdr)

The output is this:

SW1#show cable-diagnostics tdr interface Gi1/0/1
TDR test last run on: December 26 11:40:35

Interface Speed Local pair Pair length        Remote pair Pair status
--------- ----- ---------- ------------------ ----------- --------------------
Gi1/0/1   1000M Pair A     55   +/- 10 meters Pair B      Normal              
                Pair B     55   +/- 10 meters Pair A      Normal              
                Pair C     55   +/- 10 meters Pair D      Normal              
                Pair D     55   +/- 10 meters Pair C      Normal 

I hope you can help me, thanks

I tried to sort output to text file but I can pass it to excel sorted.

pepex7
  • 1
  • 1

1 Answers1

0

This isn't a perfect solution, but it will get you pretty close.

  • Copy & Paste into Excel

Excel will paste all the data into a single column

EXCEL

  • Highlight the data you want to split into multiple columns. Select Data tab, and Text to Columns

enter image description here

  • Select 'Delimited' and click Next

enter image description here

  • Select 'Tab' 'Space' and 'Treat consecutive delimiters as one', click Finish

enter image description here

enter image description here

  • In your case to get things to line up perfectly you need to highlight a7:a9 and insert, shift cells right

enter image description here

enter image description here

enter image description here

Kaleb Fenley
  • 216
  • 1
  • 5
  • thank you for you comment. it is not well ordered. headers are scrolled. The idea would be to automate obtaining the data and for the output to come out in order. – pepex7 Jan 03 '23 at 21:21
  • I understand, maybe this similar answer will help you to move forward. Looks like they are using python to convert the output of sh ip int b to a csv. You could probably re-use most, if not all, of that code to suit your needs as well. [Answer](https://stackoverflow.com/a/73992862/20914165) – Kaleb Fenley Jan 03 '23 at 22:02