Przeglądaj źródła

Get all ip if ip=0.0.0.0

Poil 11 lat temu
rodzic
commit
b1cd86d94c
2 zmienionych plików z 7 dodań i 29 usunięć
  1. 3 12
      functions/fn_autoip
  2. 4 17
      functions/fn_check_ip

+ 3 - 12
functions/fn_autoip

@@ -12,17 +12,8 @@ if [ ! -f /bin/ip ]; then
 else
 	ipcommand="ip"
 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)
+getip=$(hostname -I)
 
 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
+	ip=${getip}
+fi

+ 4 - 17
functions/fn_check_ip

@@ -7,22 +7,9 @@
 # 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 [ ! -f /bin/ip ]; then
-	ipcommand="/sbin/ip"
-else
-	ipcommand="ip"
-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)
+getip=$(hostname -I)
 
 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
+	ip=${getip}
+fi
+