Python Forum
Issue when running telnet program using python3 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Issue when running telnet program using python3 (/thread-14871.html)

Pages: 1 2


RE: Issue when running telnet program using python3 - searching1 - Dec-21-2018

I think, I'm close finish this up. :))
if password:
        tn.read_until(b"Password:")
        tn.write(password.encode("ascii")+b"\n") 

        tn.read_until(b"#")
        tn.write(b"conf t"+b"\n")
        time.sleep(1)
        tn.write(b"hostname test1"+b"\n")
        tn.write(b"exit"+b"\n")
        tn.write(b"terminal length 0"+b"\n")
        tn.write(b"show run"+b"\n")
##        time.sleep(5)
        
#Save method
        readoutput = tn.read_all()
        tn.write(b"exit"+b"\n")
        saveoutput = open("device" + HOST, "w")
        saveoutput.write(str(readoutput))
        saveoutput.close
        tn.close()
    break
Put a break at the end, and I eliminate the socket error.. But there no data on the file named as device.


RE: Issue when running telnet program using python3 - searching1 - Dec-22-2018

Removed the break for the loop to continue, but Got a new issue... I'm able to finish all task in function like change hostname copy and export the cofig but only for 1 device other device just successfully change the hostname but the writing the configuration into the file that has been created.. :(

https://stackoverflow.com/questions/53892212/script-issue-copying-config-into-a-file