forked from p15670423/monkey
Agent: Gracefully handle character decode errors in ping command
This commit is contained in:
parent
5f9e507dc7
commit
54e519eeaa
|
@ -38,22 +38,24 @@ class PingScanner(HostScanner, HostFinger):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_host_fingerprint(self, host):
|
def get_host_fingerprint(self, host):
|
||||||
|
|
||||||
timeout = self._config.ping_scan_timeout
|
timeout = self._config.ping_scan_timeout
|
||||||
if not "win32" == sys.platform:
|
if not "win32" == sys.platform:
|
||||||
timeout /= 1000
|
timeout /= 1000
|
||||||
|
|
||||||
ping_cmd = ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(timeout), host.ip_addr]
|
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)}")
|
LOG.debug(f"Running ping command: {' '.join(ping_cmd)}")
|
||||||
|
|
||||||
|
# If stdout is not connected to a terminal (i.e. redirected to a pipe or file), the result
|
||||||
|
# of os.device_encoding(1) will be None. Setting errors="backslashreplace" prevents a crash
|
||||||
|
# in this case. See #1175 and #1403 for more information.
|
||||||
|
encoding = os.device_encoding(1)
|
||||||
sub_proc = subprocess.Popen(
|
sub_proc = subprocess.Popen(
|
||||||
ping_cmd,
|
ping_cmd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
encoding=encoding,
|
encoding=encoding,
|
||||||
|
errors="backslashreplace",
|
||||||
)
|
)
|
||||||
|
|
||||||
LOG.debug(f"Retrieving ping command output using {encoding} encoding")
|
LOG.debug(f"Retrieving ping command output using {encoding} encoding")
|
||||||
|
|
Loading…
Reference in New Issue