code: def is_internet_on(host="8.8.8.8", port=53, timeout=3):
      
      socket.setdefaulttimeout(timeout)
      socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
docs: Checks if machine has internet connection
  
      :param host: hostname to test
      :param port: port of hostname
      :param timeout: seconds before discarding connection
      :return: True iff machine has internet connection