Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
I am new one for python trying to take telnet from my windows7 pc to another windows PC using below script. 


import telnetlib
import os

host_ip = "10.22.7.3"
user = "user"
password = "user"
tnet_hndl = telnetlib.Telnet(host_ip)
print (tnet_hndl.read_until(b"login: "))
tnet_hndl.write(user.encode('ascii') + b"\r\n")
print (tnet_hndl.read_until(b"password: "))
tnet_hndl.write(password.encode('ascii') + b"\r\n")
print (tnet_hndl.read_until(b"# "))
tnet_hndl.write(b"" + b"\r\n")
print (tnet_hndl.read_until(b"# "))
tnet_hndl.close()

I am getting below error
------------------------------------

login: 
user



Timeout expired!



Traceback (most recent call last):
  File "C:/Python27/telnet123.py", line 12, in <module>
    print (tnet_hndl.read_until(b"# "))
  File "C:\Python27\lib\telnetlib.py", line 295, in read_until
    return self._read_until_with_select(match, timeout)
  File "C:\Python27\lib\telnetlib.py", line 378, in _read_until_with_select
    return self.read_very_lazy()
  File "C:\Python27\lib\telnetlib.py", line 454, in read_very_lazy
    raise EOFError, 'telnet connection closed'
EOFError: telnet connection closed</module>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900