-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibarphelper.sh
executable file
·55 lines (53 loc) · 1.49 KB
/
libarphelper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
function arp_mac_to_dns() {
all_results=$(/usr/sbin/arp -a)
declare -A mac_to_dns;
OLDIFS=$IFS
IFS=$'\n'
for item in $all_results; do
IFS=' '
read -r dns ip at mac eth on port <<< "$item"
if [[ "$dns" == "?" || $mac == "<incomplete>" ]]; then
continue;
fi
mac_to_dns["$mac"]="$dns"
done
IFS=OLDIFS
declare -p mac_to_dns
}
function arp_mac_to_ip() {
all_results=$(/usr/sbin/arp -a)
declare -A mac_to_ip;
OLDIFS=$IFS
IFS=$'\n'
for item in $all_results; do
IFS=' '
read -r dns ip at mac eth on port <<< "$item"
if [[ $mac == "<incomplete>" ]]; then
continue;
fi
ip=${ip#*(}
ip=${ip%)*}
mac_to_ip["$mac"]="$ip"
done
IFS=OLDIFS
declare -p mac_to_ip
}
function arp_ip_to_mac() {
all_results=$(/usr/sbin/arp -a)
declare -A ip_to_mac;
OLDIFS=$IFS
IFS=$'\n'
for item in $all_results; do
IFS=' '
read -r dns ip at mac eth on port <<< "$item"
if [[ $mac == "<incomplete>" ]]; then
continue;
fi
ip=${ip#*(}
ip=${ip%)*}
ip_to_mac["$ip"]="$mac"
done
IFS=OLDIFS
declare -p ip_to_mac
}