import subprocess class Ping: host: str _cmd: list[str] def __init__(self, host: str): self.host = host self._cmd = ["/usr/bin/ping", "-c", "1", "-W", "1", "-qn", self.host] def ping(self) -> bool: try: subprocess.run( self._cmd, shell=False, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) return True except subprocess.CalledProcessError: return False