1

I am new to python scripting, but I have made a script that works with other devices on my network. I am trying to modify a script that will instruct the remote device to backup its config to a TFTP server. It works fine for my 3Com, HP switches, but I just added a DLINK POE switch that it dies on. The Code is as follows.

import getpass
import sys
import telnetlib

HOST = "10.3.5.90"
user = "admin"
password = "Password"

tn = telnetlib.Telnet(HOST)

tn.read_until("DGS-12010-10P login: ")
tn.write(user + "\r")
tn.read_until("Password: ")
tn.write(password + "\r")
tn.read_until("DGS-1210-10P> ")
tn.write("upload cfg_toTFTP tftp://10.5.5.2/DGS-1210-10P.bin" + "\r")
tn.read_until("DGS-1210-10P> ")
tn.write("logout" + "\r")
tn.close()

print "Backup Complete POE Switch"

I always get the output below and it times out. I can't figure out what I'm doing wrong since it works with 30+ devices with no hiccups

Traceback (most recent call last):
File "/backup/scripts/05-POE-switch.py", line 13, in <module>
tn.read_until("Password: ")
File "/usr/lib/python2.7/telnetlib.py", line 319, in read_until
return self.read_very_lazy()
File "/usr/lib/python2.7/telnetlib.py", line 395, in read_very_lazy
raise EOFError, 'telnet connection closed'

Thank you in advance for you help.

2
  • does it work if you telnet to the device manually? Does it emit the exact responses that you're waiting for in the script? Commented Dec 17, 2013 at 17:54
  • If I telnet to the device manually and type the commands in, it works and TFTPs the file to my server. The responses are when I try to execute the Python Script Commented Dec 17, 2013 at 19:40

1 Answer 1

1

Try to send \r\n instead of just \r as end-of-line terminator. I think it's your problem.

Otherwise, use wireshark to monitor the TCP communication between a "manual" telnet session and your device: you will see what it sends exactly and you will see what you have to send...

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like I'm pulling out wireshark. Changing it to ''\r\n'' didn't work
Any news on this? Did you find the solution to your problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.