From fba709845882782544f9d96433dc652de8aca8b6 Mon Sep 17 00:00:00 2001 From: Duncan Greene Date: Mon, 15 Jun 2026 14:58:10 +0100 Subject: [PATCH] Add retry mechanism to get_ipv4_addr --- modules/test/base/bin/get_ipv4_addr | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/test/base/bin/get_ipv4_addr b/modules/test/base/bin/get_ipv4_addr index c244b157d..af8262046 100644 --- a/modules/test/base/bin/get_ipv4_addr +++ b/modules/test/base/bin/get_ipv4_addr @@ -17,6 +17,22 @@ NET=$1 MAC=$2 -IP_ADDR=$(nmap -sP $NET | grep -B 2 $MAC | head -n 1 | cut -d " " -f 5) +# Some devices intermittently do not answer a given ARP request, so a single +# nmap sweep can miss a device that is in fact present. Retry the sweep a few +# times (each retry issues fresh ARP requests) before giving up, so one dropped +# reply does not cause resolution to fail. +RETRIES=4 +RETRY_DELAY=2 + +IP_ADDR="" +for attempt in $(seq 1 "$RETRIES"); do + IP_ADDR=$(nmap -sP $NET | grep -B 2 $MAC | head -n 1 | cut -d " " -f 5) + if [ -n "$IP_ADDR" ]; then + break + fi + if [ "$attempt" -lt "$RETRIES" ]; then + sleep "$RETRY_DELAY" + fi +done echo $IP_ADDR \ No newline at end of file