Agent: Deduplicate ping command list in PingScanner

This commit is contained in:
Mike Salvatore 2021-08-19 13:27:40 -04:00
parent 1d9372690d
commit 1f519ad1ee
1 changed files with 7 additions and 4 deletions

View File

@ -29,14 +29,17 @@ class PingScanner(HostScanner, HostFinger):
self._ttl_regex = re.compile(TTL_REGEX_STR, re.IGNORECASE)
def is_host_alive(self, host):
ping_cmd = self._build_ping_command(host.ip_addr)
LOG.debug(f"Running ping command: {' '.join(ping_cmd)}")
return 0 == subprocess.call(
["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(self._timeout), host.ip_addr],
ping_cmd,
stdout=self._devnull,
stderr=self._devnull,
)
def get_host_fingerprint(self, host):
ping_cmd = ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(self._timeout), host.ip_addr]
ping_cmd = self._build_ping_command(host.ip_addr)
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
@ -72,5 +75,5 @@ class PingScanner(HostScanner, HostFinger):
return False
def _build_ping_command(self, host):
return ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(self._timeout), host.ip_addr]
def _build_ping_command(self, ip_addr):
return ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(self._timeout), ip_addr]