From 61a054f3764c5418eb2fe987e67d595e36b062ab Mon Sep 17 00:00:00 2001 From: cediackermann Date: Fri, 24 Apr 2026 11:09:46 +0200 Subject: [PATCH] Speed up Ollama host detection using ARP table + parallel checks Instead of sequentially probing all 254 IPs in the subnet (worst case ~4 minutes), read the ARP table for devices already visible on the network and check all of them for port 11434 simultaneously. Completes in roughly one nc timeout (~1s) regardless of network size. --- setup_onyx.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/setup_onyx.sh b/setup_onyx.sh index dfbecd2..a5a3654 100755 --- a/setup_onyx.sh +++ b/setup_onyx.sh @@ -74,24 +74,28 @@ detect_ollama_host() { return fi - local LOCAL_IP - LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null || echo "") - if [ -z "$LOCAL_IP" ]; then + # Get IPs of devices currently visible on the network from the ARP table + local ARP_IPS + ARP_IPS=$(arp -a 2>/dev/null | grep -v incomplete | grep -oE '\(([0-9]{1,3}\.){3}[0-9]{1,3}\)' | tr -d '()') + if [ -z "$ARP_IPS" ]; then echo "" return fi - local SUBNET - SUBNET=$(echo "$LOCAL_IP" | cut -d. -f1-3) - - print_warning "Ollama not found locally — scanning ${SUBNET}.0/24 for Ollama..." + print_warning "Ollama not found locally — checking $(echo "$ARP_IPS" | wc -l | tr -d ' ') network devices in parallel..." + # Check all ARP devices for port 11434 simultaneously + local TMPFILE + TMPFILE=$(mktemp) + while IFS= read -r ip; do + ( nc -z -w 1 "$ip" 11434 2>/dev/null && echo "$ip" >> "$TMPFILE" ) & + done <<< "$ARP_IPS" + wait local FOUND=() - for i in $(seq 1 254); do - if nc -z -w 1 "${SUBNET}.${i}" 11434 2>/dev/null; then - FOUND+=("${SUBNET}.${i}") - fi - done + while IFS= read -r ip; do + FOUND+=("$ip") + done < "$TMPFILE" + rm -f "$TMPFILE" if [ ${#FOUND[@]} -eq 1 ]; then echo "${FOUND[0]}"