Make more script friendly (throw exception vs die) and a few other tweak...

Hi!

Not sure if I'm doing this right, if not let me know :)

I'm using the code to automate some stuff, however if it died then I couldn't gracefully handle the error. Also ran into an infinite loop in get_rpc_reply(), so coded in a timeout. 

For optimization set a connect timeout and handle that error specifically as well. ( we have a huge number of switches, and sometimes they are down :)

Thanks!
Thomas