-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar-test.sh
executable file
·154 lines (128 loc) · 3.38 KB
/
registrar-test.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
set -e
set -u
_check_requirements() {
if ! command -v sipp &>/dev/null; then
echo "SIPp could not be found. Please install before using this script."
return 1
fi
return 0
}
_read_known_registrars() {
local _known_registrars_file
local _registrars
local _line
_registrars=""
_known_registrars_file="${PWD}/known_registrars"
while IFS= read -r _line; do
if [[ $_line != \#* ]]; then
_registrars="${_registrars}${_line}, "
fi
done <"$_known_registrars_file"
echo "${_registrars%,}"
return 0
}
_initiate_test() {
local _line
local _details
local _second_ip
local _ipv4
_line="${3}"
_ipv4=false
_second_ip=false
IFS=' ' read -r -a _details <<<"$_line"
if [[ ${_details[1]} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
_ipv4=true
fi
if [[ -v "_details[2]" ]]; then
_second_ip=true
fi
if sipp ${_details[0]} -aa -d 30 -r 1 -rp 1s -sf sipp_scenario.xml -l 1 -m 1 -ap ${2} -s ${1} &>/dev/null; then
if [ "$_ipv4" = true ]; then
if [ "$_second_ip" = true ]; then
if [ ${#_details[2]} -lt 24 ]; then
echo -e "${_details[0]}\t${_details[1]}\t\t\t${_details[2]}\t\t\e[92mSuccess\e[39m"
else
echo -e "${_details[0]}\t${_details[1]}\t\t\t${_details[2]}\t\e[92mSuccess\e[39m"
fi
else
echo -e "${_details[0]}\t${_details[1]}\t\t\tN/A\t\t\t\t\e[92mSuccess\e[39m"
fi
else
if [ ${#_details[1]} -lt 24 ]; then
echo -e "${_details[0]}\t${_details[1]}\t\tN/A\t\t\t\t\e[92mSuccess\e[39m"
else
echo -e "${_details[0]}\t${_details[1]}\tN/A\t\t\t\t\e[92mSuccess\e[39m"
fi
fi
else
if [ "$_ipv4" = true ]; then
if [ "$_second_ip" = true ]; then
if [ ${#_details[2]} -lt 24 ]; then
echo -e "${_details[0]}\t${_details[1]}\t\t\t${_details[2]}\t\t\e[91mFailed\e[39m"
else
echo -e "${_details[0]}\t${_details[1]}\t\t\t${_details[2]}\t\e[91mFailed\e[39m"
fi
else
echo -e "${_details[0]}\t${_details[1]}\t\t\tN/A\t\t\t\t\e[91mFailed\e[39m"
fi
else
if [ ${#_details[1]} -lt 24 ]; then
echo -e "${_details[0]}\t${_details[1]}\t\tN/A\t\t\t\t\e[91mFailed\e[39m"
else
echo -e "${_details[0]}\t${_details[1]}\tN/A\t\t\t\t\e[91mFailed\e[39m"
fi
fi
fi
return 0
}
_test_registrars() {
local _registrars
local _registrar_lines
local _line
_registrars="${3}"
IFS=',' read -r -a _registrar_lines <<<"$_registrars"
echo -e "REGISTRAR\t\t\tIP\t\t\t\t2. IP\t\t\t\tSTATUS"
for _line in "${_registrar_lines[@]}"; do
if [[ ! -z "${_line// /}" ]]; then
_initiate_test "${1}" "${2}" "${_line}"
fi
done
return 0
}
_main() {
local _registrars
local _user
local _password
_password=""
if test ${#} -eq 0; then
echo "Please provider SIP username."
return 0
fi
while getopts ":u:p" opt; do
case ${opt} in
u)
_user=$OPTARG
;;
p)
echo -n "Please enter your SIP password:"
read -s _password
echo ""
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
return 1
;;
:)
echo "Invalid option: $OPTARG requires an argument" 1>&2
return 1
;;
esac
done
shift $((OPTIND - 1))
_check_requirements
_registrars="$(_read_known_registrars)"
_test_registrars "${_user}" "${_password}" "${_registrars}"
return 0
}
_main "${@}"