Created
July 6, 2025 11:13
-
-
Save revilon1991/191844c98544bcdd71d4ff57987cb63d to your computer and use it in GitHub Desktop.
Find a ip's a local server by mac address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findMinix() { | |
local subnet="192.168.2" | |
local enp1s0_mac="a0:1e:0b:0e:81:14" | |
local wlan0_mac="cc:4b:73:8e:6c:8a" | |
normalize_mac_simple() { | |
echo "$1" | tr '[:upper:]' '[:lower:]' | awk -F: '{ | |
for(i=1;i<=NF;i++) { | |
sub(/^0+/, "", $i); | |
printf "%s%s", $i, (i==NF ? "\n" : ":") | |
} | |
}' | |
} | |
local norm_enp1s0_mac | |
local norm_wlan0_mac | |
norm_enp1s0_mac=$(normalize_mac_simple "$enp1s0_mac") | |
norm_wlan0_mac=$(normalize_mac_simple "$wlan0_mac") | |
echo "[*] Сканируем подсеть $subnet.0/24..." | |
# Параллельный пинг с xargs, подавляем вывод | |
seq 1 254 | xargs -P 50 -I{} ping -c 1 -W 1 "$subnet.{}" >/dev/null 2>&1 | |
echo "[*] Проверяем ARP таблицу..." | |
arp -a | grep "$subnet" | while read -r line; do | |
ip=$(echo "$line" | awk -F'[()]' '{print $2}') | |
raw_mac=$(echo "$line" | grep -oE '([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}') | |
norm_mac=$(normalize_mac_simple "$raw_mac") | |
if [[ "$norm_mac" == "$norm_enp1s0_mac" ]]; then | |
echo "$ip" | |
fi | |
if [[ "$norm_mac" == "$norm_wlan0_mac" ]]; then | |
echo "$ip" | |
fi | |
done | |
echo "Done" | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment