Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save outputs to Desktop
#1
Hello,

I wrote my first script.
It is logging to 2 Router's console\CLI and executing few commands.
Afterwards in Router's console I have outputs which shows me for example IP Addresing
Output:
R1#sho ip int bri Interface IP-Address OK? Method Status Protocol Ethernet0/0 unassigned YES unset administratively down down Ethernet0/1 unassigned YES unset administratively down down Ethernet0/2 unassigned YES unset administratively down down Ethernet0/3 unassigned YES unset administratively down down Loopback0 1.1.1.1 YES manual up up Loopback1 2.2.2.2 YES manual up up R1#show interface description Interface Status Protocol Description Et0/0 admin down down Et0/1 admin down down Et0/2 admin down down Et0/3 admin down down Lo0 up up Lo1 up up R1#
My question is how to save those outputs to my Desktop in text document format.


import getpass
import sys
import telnetlib

print ("Script starts")

HOST = "71.61.14.36"

tn = telnetlib.Telnet(HOST, "33153",)
print ("Telnetting to device")

tn2 = telnetlib.Telnet(HOST, "33154",)
print ("Telnetting to device")


print ("Executing commands")
tn.write("\n\n\n\n")
tn.write("\n\n\n\n")
tn.write("enable\n")
tn.write("show ip interface brief\n")
tn.write("show interfaces description\n")


print ("Executing commands")
tn2.write("\n\n\n\n")
tn2.write("\n\n\n\n")
tn2.write("enable\n")
tn2.write("show ip interface brief\n")
tn2.write("show interfaces description\n")
tn2.close()
Reply
#2
I don't have the answer, but there is an impressive wrapper of telnetlib with logging capabilities in the robotframework source code, you could perhaps find ideas here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  format json outputs ! evilcode1 3 1,692 Oct-29-2023, 01:30 PM
Last Post: omemoe277
  how to save to multiple locations during save cubangt 1 509 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Formatting outputs created with .join command klairel 2 593 Aug-23-2023, 08:52 AM
Last Post: perfringo
  I have written a program that outputs data based on GPS signal kalle 1 1,133 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  Why does absence of print command outputs quotes in function? Mark17 2 1,341 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,448 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  Combining outputs into a dataframe rybina 0 1,649 Mar-15-2021, 02:43 PM
Last Post: rybina
  ONE input => THREE outputs Tricia279 6 2,560 Jan-14-2021, 08:52 AM
Last Post: perfringo
  Multi set string inputs/outputs kwmcgreal 2 2,008 Sep-26-2020, 10:44 PM
Last Post: kwmcgreal
  How to use subprocess to get multiple data outputs in desired folder? 3SG14 1 2,165 Sep-19-2020, 05:46 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020