Hello daniweb,
This is my first post, and coincidentally my first program! (more like a script though I am told)
At my work there is a lot of programmers, unfortunately they do not like Python. I cannot agree with their sentiment! It is my first language (computer wise) and so far from what I have read makes be believe that if I can harness it, I will be able to perform repetitive tasks with more ease! Below is my first code, a telnet script, I am having trouble trying to catch certain exceptions, namely the EOFError. What is the best way to try to catch multiple exceptions? Also if somebody could point out if I am heading down the right path here? I realise that if i start bad habits early on in programming, it will stay with me for life (or be very hard to break) I am very open to suggestion so any feedback would be great.
import socket, sys
import telnetlib
import time
print "Hello, welcome to helpdesks Tandberg PW Checker"
HOST = raw_input("Enter the Tandberg IP > ")
try:
c = telnetlib.Telnet(HOST)
except socket.gaierror, e:
print "Connection error to", HOST,"is the host up?" #% e
sys.exit(1)
c = telnetlib.Telnet(HOST)
try:
c.read_until('Password: ', 5)
c.write(<snipped>)
c.read_until('OK')
print HOST, "Password = ****"
c.write('exit\r')
sys.exit(1)
except EOFError, error:
c = telnetlib.Telnet(HOST)
c.read_until('Password: ', 5)
c.write(<snipped>)
c.read_until('OK')
print 'Password = ****'
c.write('exit\r')
sys.exit(1)
c.read_all()
I am looking to catch an error for when the password is neither of the 2 defaults. And returning say print "the password is other than the default!"
Any ideas?