41 lines
791 B
Plaintext
41 lines
791 B
Plaintext
|
#!/bin/bash
|
||
|
valid_ip()
|
||
|
{
|
||
|
local ip=$1
|
||
|
local stat=1
|
||
|
local res
|
||
|
|
||
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||
|
OIFS=$IFS
|
||
|
IFS='.'
|
||
|
ip=($ip)
|
||
|
IFS=$OIFS
|
||
|
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||
|
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||
|
res=$([ $? == 0 ] && echo true || echo false)
|
||
|
else
|
||
|
res=false
|
||
|
fi
|
||
|
echo $res
|
||
|
}
|
||
|
|
||
|
get_domain() {
|
||
|
local domain
|
||
|
domain=$(echo $1 | awk -F\. '{print $(NF-1) FS $NF}')
|
||
|
echo "$domain"
|
||
|
}
|
||
|
|
||
|
# must be json as a string, depends on jq
|
||
|
get_prop_value () {
|
||
|
local value
|
||
|
# echo in $1 get $2
|
||
|
value=$(echo $1 | jq -r .$2)
|
||
|
echo $value
|
||
|
}
|
||
|
|
||
|
|
||
|
is_array() {
|
||
|
local variable_name=$1
|
||
|
[[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]]
|
||
|
}
|