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
  Multi set string inputs/outputs kwmcgreal 2 255 Sep-26-2020, 10:44 PM
Last Post: kwmcgreal
  How to use subprocess to get multiple data outputs in desired folder? 3SG14 1 329 Sep-19-2020, 05:46 PM
Last Post: bowlofred
  Outputs missing SamAnw 4 466 Feb-12-2020, 04:32 PM
Last Post: adetheheat
  Interpreter and running a .py file give different outputs PythonNPC 5 753 Jul-21-2019, 01:07 PM
Last Post: PythonNPC
  Help Editing/Problem with outputs stanthaman42 7 1,552 Jul-11-2018, 05:30 PM
Last Post: ichabod801
  how do i rewrite this code to give me 10 outputs BlackPimpernel 2 1,048 Mar-29-2018, 11:29 AM
Last Post: BlackPimpernel
  Different outputs in Python2 and Python3 MikeHill 3 2,030 Jun-07-2017, 08:58 PM
Last Post: Ofnuts
  Program that outputs HQ addresses of companies from Google + Local pages frenchgirl1309 2 2,242 Nov-14-2016, 10:11 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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