#!/bin/bash # Sharada Audio local web-interface finder for macOS, version 1. # Compatible with the macOS-supplied Bash 3.2. No installs or sudo required. # Reads HTTP pages only. Does not log in, change settings or follow redirects. PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH export LC_ALL=C if [ "$(uname -s)" != Darwin ]; then echo 'This finder is for macOS. Windows users should download the .ps1 version.' exit 1 fi for tool in networksetup ifconfig curl awk grep head mktemp; do if ! command -v "$tool" >/dev/null 2>&1; then echo "Required macOS tool is missing: $tool. Please contact Sharada Audio." exit 1 fi done work_dir=$(mktemp -d "${TMPDIR:-/tmp}/sharada-finder.XXXXXX") || exit 1 cleanup() { wait # Remove only files made by this run, not the enclosing temp directory. rm -f "$work_dir"/page-* "$work_dir"/match-* rmdir "$work_dir" 2>/dev/null } trap cleanup EXIT trap 'exit 130' INT TERM check_page() { local address=$1 body="$work_dir/page-$1" # No proxy, credentials, redirects or external hostnames. Limit read size/time. curl --silent --noproxy '*' --proto '=http' --connect-timeout 1 --max-time 2 \ "http://$address/" 2>/dev/null | head -c 131072 > "$body" # A shared management-page signature is only a possible match. if grep -Eiq 'SE106[[:space:]]*Pro|Sharada[[:space:]]*Audio' "$body" || { grep -Eiq 'g_product[[:space:]]*=[[:space:]]*0[[:space:]]*;' "$body" && grep -Eiq 'mercurycom\.com\.cn' "$body"; }; then printf '%s\n' "$address" > "$work_dir/match-$address" fi rm -f "$body" } echo 'Sharada Audio - finding possible regenerator settings pages.' echo 'No settings will be changed. Please allow a minute or two.' echo 'If macOS asks for local network access, allow it for this search.' scanned=0 interfaces=$(networksetup -listallhardwareports 2>/dev/null | awk '/^Device: / {print $2}') for interface in $interfaces; do config=$(ifconfig "$interface" 2>/dev/null) printf '%s\n' "$config" | grep -q 'status: active' || continue ip=$(printf '%s\n' "$config" | awk '$1=="inet" {print $2; exit}') mask=$(printf '%s\n' "$config" | awk '$1=="inet" {for(i=1;i 1024 || (size & (size-1)) != 0 )); then echo "Skipping $interface: only common /22 through /30 local networks are scanned." continue fi IFS=. read -r a b c d <<< "$ip" number=$(( (10#$a << 24) + (10#$b << 16) + (10#$c << 8) + 10#$d )) network=$(( number & mask )) echo "Checking $interface ($ip)..." scanned=$((scanned+1)) batch=0 for ((n=network+1; n= 24 )); then wait; batch=0; fi done wait done found=0 for result in "$work_dir"/match-*; do [ -f "$result" ] || continue read -r address < "$result" echo "Possible regenerator settings page: http://$address/" found=$((found+1)) done if (( found > 0 )); then echo 'Open the result in your browser. Confirm it is your regenerator before signing in.' echo 'Similar devices may also appear. Send multiple or uncertain results to Sharada Audio.' else echo 'No recognisable settings page was found. This does not prove the unit is offline.' (( scanned == 0 )) && echo 'No supported active home-network connection was found.' echo 'Check power and use the same home network; avoid guest Wi-Fi and disconnect a VPN.' echo 'If local network permission was denied, review System Settings > Privacy & Security > Local Network.' fi echo 'Different login-page software or an address outside your home network can prevent discovery.' echo 'Contact Sharada Audio if no result appears or you are unsure which device was found.'