Compare commits
2 commits
caa8609908
...
850d656169
| Author | SHA1 | Date | |
|---|---|---|---|
| 850d656169 | |||
| 93c6b838a7 |
1 changed files with 9 additions and 4 deletions
|
|
@ -153,14 +153,19 @@ MAC_LOWER="$(echo "$MAC" | tr 'A-Z' 'a-z')"
|
||||||
IP=""
|
IP=""
|
||||||
deadline=$((SECONDS + 150))
|
deadline=$((SECONDS + 150))
|
||||||
while (( SECONDS < deadline )); do
|
while (( SECONDS < deadline )); do
|
||||||
|
# Capture-then-parse instead of piping directly into awk. `awk '... exit'`
|
||||||
|
# exits on first match, which SIGPIPEs the upstream arp-scan (exit 141).
|
||||||
|
# With `set -o pipefail` active that kills the whole script — exactly what
|
||||||
|
# happened the first time host-networking gave arp-scan real matches.
|
||||||
|
SCAN=""
|
||||||
if command -v arp-scan >/dev/null 2>&1; then
|
if command -v arp-scan >/dev/null 2>&1; then
|
||||||
IP="$(sudo arp-scan --localnet --quiet --ignoredups 2>/dev/null \
|
SCAN="$(sudo arp-scan --localnet --quiet --ignoredups 2>/dev/null || true)"
|
||||||
| awk -v m="$MAC_LOWER" 'tolower($2) == m { print $1; exit }')"
|
IP="$(awk -v m="$MAC_LOWER" 'tolower($2) == m { print $1; exit }' <<<"$SCAN")"
|
||||||
fi
|
fi
|
||||||
if [[ -z "$IP" ]] && command -v nmap >/dev/null 2>&1; then
|
if [[ -z "$IP" ]] && command -v nmap >/dev/null 2>&1; then
|
||||||
sudo nmap -sn -T4 192.168.178.0/24 >/dev/null 2>&1 || true
|
sudo nmap -sn -T4 192.168.178.0/24 >/dev/null 2>&1 || true
|
||||||
IP="$(ip neigh show \
|
NEIGH="$(ip neigh show)"
|
||||||
| awk -v m="$MAC_LOWER" 'tolower($5) == m && $1 ~ /^[0-9]/ { print $1; exit }')"
|
IP="$(awk -v m="$MAC_LOWER" 'tolower($5) == m && $1 ~ /^[0-9]/ { print $1; exit }' <<<"$NEIGH")"
|
||||||
fi
|
fi
|
||||||
[[ -n "$IP" ]] && break
|
[[ -n "$IP" ]] && break
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue