Here is a snippet of code that may work for you: #----------------------------------- import telnetlib
HOST = "myServer" Username = "bob" Password = "fido" LoginList = ['=login:', '%s=password:' % (Username), '%s=$' % (Password)] ## Like an Expect script Terminator = "$" print "CONNECTING:" Telnet = telnetlib.Telnet(HOST) i = 0 for LoginPair in LoginList: LoginPair = LoginPair.split("=") if i > 0: Telnet.write(LoginPair[0] + "\n") x = Telnet.read_until(LoginPair[1]) print x i = i + 1 print "CONNECTED:" CommandLine = "ls -l\n" Telnet.write(CommandLine) Blob = Telnet.read_until(Terminator) print Blob #----------------------------------- -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Monday, October 16, 2006 12:19 PM To: Kent Johnson Cc: tutor@python.org Subject: Re: [Tutor] Capture telnet output to a file? That looks like it will do what I want. Thank You! ----- Original Message ----- From: Kent Johnson <[EMAIL PROTECTED]> Date: Monday, October 16, 2006 2:06 pm Subject: Re: [Tutor] Capture telnet output to a file? To: [EMAIL PROTECTED] Cc: tutor@python.org > [EMAIL PROTECTED] wrote: > > Hello, > > > > I am trying to capture telnet output to a file. For example I > want to > > telnet into a router and run the command "show arp" and be able to > > capture all the arp information that normally would show up on the > > screen to a file on my system. I am using python and pexpect to > > backup my router configurations on a daily basis, but for this the > > router has the option to send the configuration via tftp to a > server,> there is no option to send normal screen data to a file. > Any ideas? > > You might be able to do this using telnetlib instead of pexpect. > > Kent > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor