diff --git a/monkey/infection_monkey/network/ping_scanner.py b/monkey/infection_monkey/network/ping_scanner.py index f43412064..38195e44b 100644 --- a/monkey/infection_monkey/network/ping_scanner.py +++ b/monkey/infection_monkey/network/ping_scanner.py @@ -43,14 +43,20 @@ class PingScanner(HostScanner, HostFinger): if not "win32" == sys.platform: timeout /= 1000 + ping_cmd = ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(timeout), host.ip_addr] + encoding = os.device_encoding(1) + + LOG.debug(f"Running ping command: {' '.join(ping_cmd)}") + sub_proc = subprocess.Popen( - ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(timeout), host.ip_addr], + ping_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, - encoding=os.device_encoding(1), + encoding=encoding, ) + LOG.debug(f"Retrieving ping command output using {encoding} encoding") output = " ".join(sub_proc.communicate()) regex_result = self._ttl_regex.search(output) if regex_result: