This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm-mac2ipv4.tests
executable file
·129 lines (113 loc) · 2.98 KB
/
mm-mac2ipv4.tests
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#
# © 2016 Meta Mesh Wireless Communities. All rights reserved.
# Licensed under the terms of the MIT license.
#
# AUTHORS
# * Jason Khanlar
#
scripts_to_test=(./mm-mac2ipv4.bash)
if [ ${#@} -gt 0 ]; then
c=0
for arg in "$@"; do
scripts_to_test[$c]="./${arg}"
((c++))
done
fi
test() {
((attempts++))
local mac=$1
local ip=$2
if [[ "$($script_to_test $mac)" != "$ip" ]]; then
echo "$mac did not resolve to $ip"
((failure++))
else
echo "$mac resolved to $ip"
fi
}
randIPv4octet1() {
randIP="100"
}
randIPv4octet2() {
# Random 96-127
((randdec=$RANDOM / 1024 + 96))
}
randIPv4octet3() {
# Random 0-255
((randdec=$RANDOM / 128))
}
randIPv4octet4() {
# Random 0-255 every other 32
((randdec=$RANDOM / 128))
((randdec=randdec - (randdec % 64 - randdec % 32)))
}
randIPMA() {
local a
randMA=("DC:9F:DB" "DC:9F:DB" "DC:9F:DB" "DC:9F:DB")
randIPv4octet1
echo $randdec
randIPv4octet2
echo $randdec
randMA[0]="${randMA[0]}:$(printf "%02X\n" $((randdec - 64)))"
randMA[1]="${randMA[1]}:$(printf "%02X\n" $randdec)"
randMA[2]="${randMA[2]}:$(printf "%02X\n" $((randdec + 64)))"
randMA[3]="${randMA[3]}:$(printf "%02X\n" $((randdec + 128)))"
randIP="$randIP.$randdec"
randIPv4octet3
randMA[0]="${randMA[0]}:$(printf "%02X\n" $randdec)"
randMA[1]="${randMA[1]}:$(printf "%02X\n" $randdec)"
randMA[2]="${randMA[2]}:$(printf "%02X\n" $randdec)"
randMA[3]="${randMA[3]}:$(printf "%02X\n" $randdec)"
randIP="$randIP.$randdec"
randIPv4octet4
randMA[0]="${randMA[0]}:$(printf "%02X\n" $randdec)"
randMA[1]="${randMA[1]}:$(printf "%02X\n" $randdec)"
randMA[2]="${randMA[2]}:$(printf "%02X\n" $randdec)"
randMA[3]="${randMA[3]}:$(printf "%02X\n" $randdec)"
randIP="$randIP.$randdec"
}
random-tests() {
for a in {1..100}; do
randIPMA
test "${randMA[0]}" "$randIP"
test "${randMA[1]}" "$randIP"
test "${randMA[2]}" "$randIP"
test "${randMA[3]}" "$randIP"
done
}
list-all-tests() {
for cur in $($script_to_test --list-all|sed 's|^\([0-9.]*\) *=> \([A-F0-9:]*\)$|\1 \2|');do
if [ $((count++ % 2)) -eq 1 ];then
testMA[$((count / 2 - 1))]=$cur
testIP[$((count / 2 - 1))]=$last
fi
last=$cur
done
for a in $(seq 0 $((${#testMA[@]}-1))); do
test ${testMA[$a]} ${testIP[$a]}
done
}
for script_to_test in "${scripts_to_test[@]}"; do
#list-all-tests
random-tests
done
fail() {
echo "There were $failure/$attempts failures."
exit 1
}
success() {
if command -v ponysay > /dev/null 2>&1; then
ponysay All tests passed.
elif command -v cowsay > /dev/null 2>&1; then
cowsay All tests passed.
elif command -v figlet > /dev/null 2>&1; then
figlet -f mini All tests passed.
else
printf "All tests passed.\n"
fi
}
if [[ $failure -gt 0 ]]; then
fail;
else
success
fi