This python (2.7) script reads credentials and input from input.txt
file for telnet test and generates the telnet output to output.txt
make sure to modify the input.txt
file accordingly for proper _ip-address_
, _user_
and _password_
.
_ip-address_ | |
_user_ | |
_password_ | |
ls | |
exit |
import getpass | |
import sys | |
import telnetlib | |
infile = open("input.txt","r") | |
outfile = open("output.txt","w") | |
HOST = infile.readline() | |
user = infile.readline() | |
password = infile.readline() | |
tn = telnetlib.Telnet(HOST) | |
tn.read_until("login: ") | |
tn.write(user + "\n") | |
if password: | |
tn.read_until("Password: ") | |
tn.write(password + "\n") | |
while True: | |
line = infile.readline() | |
if not line: | |
break | |
tn.write(line) | |
outfile.write(tn.read_all().decode('ascii')) | |
infile.close() | |
outfile.close() |