From 5f9e507dc7d98ddcd16a83db64aefe04ce9b5c85 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 17 Aug 2021 11:24:12 -0400 Subject: [PATCH] Agent: Add debug logging to get_host_fingerprint() --- monkey/infection_monkey/network/ping_scanner.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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: