From 464642458e36f62bcccb4f0fb5013577acc62c2f Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 30 May 2022 21:42:44 +0300 Subject: [PATCH] Fix to get only first (main) IP from the interface --- slib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slib.sh b/slib.sh index c5c18f7..c915745 100644 --- a/slib.sh +++ b/slib.sh @@ -431,7 +431,7 @@ setconfig () { # works across most Linux and FreeBSD (maybe) detect_ip () { defaultdev=$(ip ro ls|grep default|head -1|awk '{print $5}') - primaryaddr=$(ip -f inet addr show dev "$defaultdev" | grep 'inet ' | awk '{print $2}' | cut -d"/" -f1 | cut -f1) + primaryaddr=$(ip -f inet addr show dev "$defaultdev" | grep 'inet ' | awk '{print $2}' | head -1 | cut -d"/" -f1 | cut -f1) if [ "$primaryaddr" ]; then log_debug "Primary address detected as $primaryaddr" address=$primaryaddr @@ -441,7 +441,7 @@ detect_ip () { echo "Please enter the name of your primary network interface: " read -r primaryinterface #primaryaddr=`/sbin/ifconfig $primaryinterface|grep 'inet addr'|cut -d: -f2|cut -d" " -f1` - primaryaddr=$(/sbin/ip -f inet -o -d addr show dev "$primaryinterface" | head -1 | awk '{print $4}' | cut -d"/" -f1) + primaryaddr=$(/sbin/ip -f inet -o -d addr show dev "$primaryinterface" | head -1 | awk '{print $4}' | head -1 | cut -d"/" -f1) if [ "$primaryaddr" = "" ]; then # Try again with FreeBSD format primaryaddr=$(/sbin/ifconfig "$primaryinterface"|grep 'inet' | awk '{ print $2 }')