Extracting data from telnet session ?

Henning Sauer hsauer at marnie.teuto.de
Sun Feb 24 18:45:50 CET 2002


Hello,

I want to extract status information from a router to which I can
connect via telnet. 
Currently I try the following:

import getpass
import sys
import telnetlib

HOST = "192.168.0.1"
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)
tn.set_debuglevel(1)
tn.read_until("Password:")
tn.write(password+"\n")

tn.write("24\n")
tn.write("1\n")
print tn.read_all()

this gets me output like this:
 
Telnet(192.168.0.1,23): recv '7;1H'
Telnet(192.168.0.1,23): recv '\033[8;1H'
Telnet(192.168.0.1,23): recv '\033[8;26H8\033[8;38H76\033[8;53H24542\033[8;65H696\033[8;79H2\033[8'
Telnet(192.168.0.1,23): recv ';1H'
Telnet(192.168.0.1,23): recv '\033[11;1H'
Telnet(192.168.0.1,23): recv '\033[12;1H'
Telnet(192.168.0.1,23): recv '\033[16;12H'
Telnet(192.168.0.1,23): recv '\033[18;23H'
Telnet(192.168.0.1,23): recv '\033[3;72H'
Telnet(192.168.0.1,23): recv '\033[4;62H'
Telnet(192.168.0.1,23): recv '\033[21;49H'
Telnet(192.168.0.1,23): recv '\033[14;22H'
Telnet(192.168.0.1,23): recv '\033[14;32H9\033[14;22H'
Telnet(192.168.0.1,23): recv '\033[7;1H'
Telnet(192.168.0.1,23): recv '\033[7;25H123\033[7;37H813\033[7;55H244\033[7;64H7121\033[7;79H6\033'
Telnet(192.168.0.1,23): recv '[7;1H'
Telnet(192.168.0.1,23): recv '\033[8;1H'
Telnet(192.168.0.1,23): recv '\033[8;25H832\033[8;37H217\033[8;54H8205\033[8;65H302\033[8;79H3\033'
Telnet(192.168.0.1,23): recv '[8;1H'
Telnet(192.168.0.1,23): recv '\033[11;1H'
Telnet(192.168.0.1,23): recv '\033[12;1H'
Telnet(192.168.0.1,23): recv '\033[16;12H'
Telnet(192.168.0.1,23): recv '\033[18;23H'
Telnet(192.168.0.1,23): recv '\033[3;72H'
Telnet(192.168.0.1,23): recv '\033[4;62H'
Telnet(192.168.0.1,23): recv '\033[21;49H'

What I would like to know is how can I extract the information 
from this data stream ? 
Is this really the data from the router or might it be debug 
information ? When I'm not setting the set_debuglevel I'm 
getting no output.
 
Bye,
Henning



More information about the Python-list mailing list