Corrected indenting to make code easier to read.
Added check for internet connectivity before trying to do address lookup.  Not sure it works though...