def haveInternetAccess(forceCheck=False):
 global haveInternet
 if (forceCheck or (haveInternet is None)):
  sites = ['http://www.google.com/', 'http://www.opendns.com/']
  for wait in [0.3, 0.7]:
   for site in sites:
    try:
     urllib.request.urlopen(site, timeout=wait)
     haveInternet = True
     return True
    except Exception:
     pass
  else:
   haveInternet = False
 return haveInternet

def haveInternetAccess ( forceCheck = False ) : global haveInternet if ( forceCheck or ( haveInternet is None ) ) : sites = [ 'http://www.google.com/' , 'http://www.opendns.com/' ] for wait in [ 0.3 , 0.7 ] : for site in sites : try : urllib . request . urlopen ( site , timeout = wait ) haveInternet = True return True except Exception : pass else : haveInternet = False return haveInternet
detect active internet connection or fail quickly .