From 5c38e906982eb38e202200405eeba01ac03b1899 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 02:19:51 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Added=20-n=20flag=20to=20skip=20reverse=20DNS=20resolution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `-n` flag skips reverse DNS resolution. Without it, ping attempts to resolve the hostname for every IP, which can cause multi-second delays (even with a 1s timeout) if the IP lacks a PTR record or DNS is unresponsive. Co-authored-by: ManupaKDU <95234271+ManupaKDU@users.noreply.github.com> --- test_testping1.py | 2 +- testping1.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test_testping1.py b/test_testping1.py index cc3f6a8..93bfd3b 100644 --- a/test_testping1.py +++ b/test_testping1.py @@ -95,7 +95,7 @@ def test_is_reachable_calls_ping_correctly(self, mock_call): is_reachable('192.168.1.1', timeout=5) # Verify that subprocess.call was called with the correct arguments, including the timeout mock_call.assert_called_once_with( - ['ping', '-c', '1', '-W', '5', '192.168.1.1'], + ['ping', '-n', '-c', '1', '-W', '5', '192.168.1.1'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=7 ) diff --git a/testping1.py b/testping1.py index 16af1e0..af17c90 100644 --- a/testping1.py +++ b/testping1.py @@ -33,7 +33,11 @@ def is_reachable(ip, timeout=1): logging.error(f"Invalid timeout value: {repr(timeout)}") return False - command = ["ping", "-c", "1", "-W", str(timeout_val), str(ip_obj)] # -W for timeout in seconds (Linux) + # ⚡ Bolt: Optimized ping execution by adding `-n` flag. + # The `-n` flag skips reverse DNS resolution. Without it, ping attempts to + # resolve the hostname for every IP, which can cause multi-second delays + # (even with a 1s timeout) if the IP lacks a PTR record or DNS is unresponsive. + command = ["ping", "-n", "-c", "1", "-W", str(timeout_val), str(ip_obj)] # -W for timeout in seconds (Linux) # ⚡ Bolt: Optimized ping execution by using subprocess.call and redirecting # output to DEVNULL instead of using Popen with PIPE.