質問

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.

正しい解決策はありません

他のヒント

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...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top