From 832d59cab24f789f71fb35cb051fdca597a63a33 Mon Sep 17 00:00:00 2001 From: ProfFan Date: Mon, 21 Mar 2016 20:00:43 +0800 Subject: [PATCH] Fix auto address detection Fixed auto address detection (There can be a better logic though) --- ddnspod.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ddnspod.sh b/ddnspod.sh index a8bc2e1..b8e5141 100755 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -12,7 +12,12 @@ case $(uname) in 'Linux') echo "Linux" arIpAddress() { - ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 + local extip + extip=$(ip -o -4 addr list | grep -Ev '\s(docker|lo)' | awk '{print $4}' | cut -d/ -f1 | grep -Ev '(^127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.1[6-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.2[0-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.3[0-1]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^192\.168\.[0-9]{1,3}\.[0-9]{1,3}$)') + if [ "x${extip}" = "x" ]; then + extip=$(ip -o -4 addr list | grep -Ev '\s(docker|lo)' | awk '{print $4}' | cut -d/ -f1 ) + fi + echo $extip } ;; 'FreeBSD')