@@ -26,32 +26,37 @@ for ethtool_command in "${ethtool_commands_array[@]}"; do
26
26
fi
27
27
done
28
28
29
- getip=$( ${ipcommand} -o -4 addr | awk ' {print $4}' | grep -oe ' \([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
30
- getipwc=$( ${ipcommand} -o -4 addr | awk ' {print $4}' | grep -oe ' \([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
29
+ mapfile -t current_ips < <( ${ipcommand} -o -4 addr | awk ' {print $4}' | grep -oe ' \([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
30
+
31
+ function fn_is_valid_ip() {
32
+ local ip=" ${1} "
33
+ # excluding 0.* ips also
34
+ grep -qEe ' ^[1-9]+[0-9]*\.[0-9]+\.[0-9]+\.[0-9]+$' <<< " ${ip}"
35
+ }
31
36
32
37
# Check if server has multiple IP addresses
33
38
34
39
# If the IP variable has been set by user.
35
- if [ -n " ${ip} " ] && [ " ${ip} " != " 0.0.0.0 " ] ; then
36
- queryips=(" ${ip} " )
37
- webadminip=(" ${ip} " )
38
- telnetip=(" ${ip} " )
40
+ if fn_is_valid_ip " ${ip} " ; then
41
+ queryips=( " ${ip} " )
42
+ webadminip=( " ${ip} " )
43
+ telnetip=( " ${ip} " )
39
44
# If game config does have an IP set.
40
- elif [ -n " ${configip} " ] && [ " ${configip} " != " 0.0.0.0 " ] ; then
41
- queryips=(" ${configip} " )
45
+ elif fn_is_valid_ip " ${configip} " ; then
46
+ queryips=( " ${configip} " )
42
47
ip=" ${configip} "
43
48
webadminip=(" ${configip} " )
44
49
telnetip=(" ${configip} " )
45
50
# If there is only 1 server IP address.
46
51
# Some IP details can automaticly use the one IP
47
- elif [ " ${getipwc } " == " 1" ]; then
48
- queryips=($( echo " ${getip} " ) )
52
+ elif [ " ${# current_ips[@] } " == " 1" ]; then
53
+ queryips=( " 127.0.0.1 " " ${current_ips[@]} " )
49
54
ip=" 0.0.0.0"
50
- webadminip=(" ${getip } " )
51
- telnetip=(" ${getip } " )
55
+ webadminip=(" ${current_ips[@] } " )
56
+ telnetip=(" ${current_ips[@] } " )
52
57
# If no ip is set by the user and server has more than one IP.
53
58
else
54
- queryips=($( echo " ${getip} " ) )
59
+ queryips=( " 127.0.0.1 " " ${current_ips[@]} " )
55
60
ip=" 0.0.0.0"
56
61
webadminip=(" ${ip} " )
57
62
telnetip=(" ${ip} " )
0 commit comments