def test_internet(host=u'8.8.8.8', port=53, timeout=3):
 try:
  socket.setdefaulttimeout(timeout)
  socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
  return True
 except Exception as ex:
  print ex.message
  return False

def test_internet ( host = u'8.8.8.8' , port = 53 , timeout = 3 ) : try : socket . setdefaulttimeout ( timeout ) socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) . connect ( ( host , port ) ) return True except Exception as ex : print ex . message return False
returns true if internet is connected host: 8 .