hi
im trying to write a python script for a telnet client. So far im able to establish a connection with a server. My problem is that i want to print (at the client) all the activities at the server end. Let me put it this way.
Suppose i send a command "dir" from my client
at the server end it would list the contents....
i would like to print the same at my client.....
is there any way i can do this....
im not sure if the data being displayed at the server's end is being transmitted through the port.
my code is including below
import telnetlib
import time
import getpass
HOST = "192.168.36.186"
PORT = 23
class MyTelnetClient():
def __init__(self,portNum=PORT,host=HOST):
self.host = host
self.portNum = portNum
self.user = raw_input('Login :')
self.password = getpass.getpass('password:')
self.tn = telnetlib.Telnet(self.host,self.portNum)
self.tn.write(self.user+"\r")
self.tn.write(self.password+"\r")
def write(self,data):
self.tn.write(data)
print data
def read(self):
self.str = self.tn.read_all()
return self.str
def close(self):
self.tn.close
if __name__ == '__main__':
TelnetClient = MyTelnetClient()
print 'Connected to Server......'
while 1:
data = str(raw_input('Telnet Client>'))
TelnetClient.write(data+"\r")
if data == 'q':
TelnetClient.tn.close()
break
else:
datarx = TelnetClient.read()
print 'TCP Server>' + datarx
print 'Closing Connection with server...'
thanks alot in advance....