Selaa lähdekoodia

Revert "Get all ip if ip=0.0.0.0"

This reverts commit b1cd86d94c5edf98eb17deb6d6bad6c77ec934e4.
Daniel Gibbs 11 vuotta sitten
vanhempi
commit
780e27fe88
2 muutettua tiedostoa jossa 29 lisäystä ja 7 poistoa
  1. 12 3
      functions/fn_autoip
  2. 17 4
      functions/fn_check_ip

+ 12 - 3
functions/fn_autoip

@@ -12,8 +12,17 @@ if [ ! -f /bin/ip ]; then
 else
 else
 	ipcommand="ip"
 	ipcommand="ip"
 fi
 fi
-getip=$(hostname -I)
+getip=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
+getipwc=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
 
 
 if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
 if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
-	ip=${getip}
-fi
+	if [ "${getipwc}" -ge "2" ]; then
+		fn_printwarn "Multiple active network interfaces found.\n\n"
+		echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
+		echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
+		echo -en "${getip}\n"
+		exit
+	else
+		ip=${getip}
+	fi
+fi

+ 17 - 4
functions/fn_check_ip

@@ -7,9 +7,22 @@
 # Description: Automatically identifies the server interface IP.
 # Description: Automatically identifies the server interface IP.
 # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
 # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
 
 
-getip=$(hostname -I)
-
-if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
-	ip=${getip}
+if [ ! -f /bin/ip ]; then
+	ipcommand="/sbin/ip"
+else
+	ipcommand="ip"
 fi
 fi
+getip=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
+getipwc=$(${ipcommand} -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
 
 
+if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
+	if [ "${getipwc}" -ge "2" ]; then
+		fn_printwarn "Multiple active network interfaces found.\n\n"
+		echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
+		echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
+		echo -en "${getip}\n"
+		exit
+	else
+		ip=${getip}
+	fi
+fi