Writing through Telnet with Python -


i'm still new python , fiddling telnet in general, i've got issue here. reason code have written doesn't stop let me write through telnet terminal, runs completion without stopping. can't figure out i'm doing wrong, can out?

import telnetlib import time host = input("ip address: ") command = b" "  tn = telnetlib.telnet(host, port = 23, timeout = 20) time.sleep(10) tn.write(command + b"\n") ret1 = tn.read_eager() time.sleep(10) print(ret1) tn.write(b"001 rq version\n") ret2 = tn.read_until(b"_dne", timeout = 5) time.sleep(10) print(ret2) tn.write(command + b"\n")  print("success!") tn.close() 

edit: sorry, should've specified more clearly.

basically, after gets ip, connects host machine fine. problem after line "tn.write(command + b"\n")", according i've looked should allow user input whatever want type in, program not stop allow user type @ all.

it looks me command empty string, , doesn't seem change @ point(except '\n'). each time tn.write(command + b"\n"), sending b"\n" down wire. you're not prompting user type anything. try like:

command = input("enter command: ") tn.write(b"{}\n".format(command)) 

in place of writing:

tn.write(command + b"\n") 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -