Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96489

How to use the returned telnet object after creating the telnet session.

Newsgroups comp.lang.python
Date 2015-09-13 00:38 -0700
Message-ID <e578698e-7721-4c01-a270-61fa211c3f79@googlegroups.com> (permalink)
Subject How to use the returned telnet object after creating the telnet session.
From manjunatha.mahalingappa@gmail.com

Show all headers | View raw


Hello all,

First I would like thank you for creating such good platform for discussing python..!!!

Assume that I will pass IP and port information from a function to open the telnet session. have opened the telnet session and after opening the telnet session I returned telnet object to calling function.

Now in the calling function If I use that object to read or write to terminal I'm getting ERROR "AttributeError: 'NoneType' object has no attribute 'read_very_eager'".


#Open telnet connection to devices

def open_telnet_conn(dname,ip,port):

try:
	TELNET_PORT = port
	TELNET_TIMEOUT = 5
	READ_TIMEOUT = 5
	cmd = "show config"
	#Logging into device

	connection=telnetlib.Telnet(ip, TELNET_PORT, TELNET_TIMEOUT)

	time.sleep(1)
	connection.write(cmd + "\n")

	#Here I'm able to write to connection object..
	connection.write("\n")
	time.sleep(2)

	router_output = connection.read_very_eager()
	print router_output

	return(connection)

except IOError:

	print "Input parameter error! Please check username, password and file name."


#Function to read device IP and port . and this info for opening the telnet session.
def IP_port(file):
T = []
F = open(file,'r')
F.seek(0)

line=F.read()
tuples = re.findall(r'(.+?)\s+(.+?)\s+(\d+)',line)

#(dname,IP,port)= tuples

for (dname,ip,port) in tuples:
	T1=open_telnet_conn(dname,ip,port)
	#HERE I will get the telnet object point to the same location as the connection object. But I'm unable to write or read anything here. I think need to convert the object T1 to TELNET CLASS object type..

	print T1
	T1.write("show config") <<<<<<<<<ERROR PART

	router_output = T1.read_very_eager()
	print router_output
	T.append(T1)
	return(T)


# import the LC/RSP name ,port and IP address
file='/users/manmahal/MANJU/IP_port.txt'
list_of_telnet=IP_port(file)



NOTE: the content of the file is as below:

RSP1 172.27.40.60 2002

RSP0 172.27.40.60 2001

LC0 172.27.40.60 2010


Idea is to create the telnet sessions store them in list or dictionary use them as and when needed.
Any thought or solution is welcome...!!!



Regards
Manju

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to use the returned telnet object after creating the telnet session. manjunatha.mahalingappa@gmail.com - 2015-09-13 00:38 -0700
  Re: How to use the returned telnet object after creating the telnet session. Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-13 10:34 +0000
  Re: How to use the returned telnet object after creating the telnet session. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-13 12:40 -0400

csiph-web