From 7543b31da59ab9517474a604b4108b459bfad8ff Mon Sep 17 00:00:00 2001 From: Michael Harder Date: Thu, 4 Feb 2016 01:08:43 -0800 Subject: [PATCH 1/2] remove default if=ppp0 if use=if to allow for getting public address from any interface --- ddclient | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddclient b/ddclient index 8eda1c5..5c497bf 100755 --- a/ddclient +++ b/ddclient @@ -330,7 +330,7 @@ my %variables = ( 'use' => setv(T_USE, 0, 0, 1, 'ip', undef), 'ip' => setv(T_IP, 0, 0, 1, undef, undef), - 'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef), + 'if' => setv(T_IF, 0, 0, 1, '', undef), 'if-skip' => setv(T_STRING,1, 0, 1, '', undef), 'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef), 'web-skip' => setv(T_STRING,1, 0, 1, '', undef), @@ -370,7 +370,7 @@ my %variables = ( 'host' => setv(T_STRING, 1, 1, 1, '', undef), 'use' => setv(T_USE, 0, 0, 1, 'ip', undef), - 'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef), + 'if' => setv(T_IF, 0, 0, 1, '', undef), 'if-skip' => setv(T_STRING,0, 0, 1, '', undef), 'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef), 'web-skip' => setv(T_STRING,0, 0, 1, '', undef), From e8532970a9f10be50bbe3112a34a10dc8886bc86 Mon Sep 17 00:00:00 2001 From: Michael Harder Date: Thu, 4 Feb 2016 01:14:22 -0800 Subject: [PATCH 2/2] allow public ip address from any interface --- ddclient | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ddclient b/ddclient index 5c497bf..eff1994 100755 --- a/ddclient +++ b/ddclient @@ -25,6 +25,7 @@ use Getopt::Long; use Sys::Hostname; use IO::Socket; use Data::Validate::IP; +use Net::Address::IP::Local; my $version = "3.8.3"; my $programd = $0; @@ -2145,10 +2146,15 @@ sub get_ip { $arg = 'ip'; } elsif ($use eq 'if') { - $skip = opt('if-skip', $h) || ''; - $reply = `ifconfig $arg 2> /dev/null`; - $reply = `ip addr list dev $arg 2> /dev/null` if $?; - $reply = '' if $?; + if ($arg eq '') { + $ip = Net::Address::IP::Local->public; + } + if (!$ip) { + $skip = opt('if-skip', $h) || ''; + $reply = `ifconfig $arg 2> /dev/null`; + $reply = `ip addr list dev $arg 2> /dev/null` if $?; + $reply = '' if $?; + } } elsif ($use eq 'cmd') { if ($arg) { @@ -2226,15 +2232,17 @@ sub get_ip { $skip =~ s/ /\\s/is; $reply =~ s/^.*?${skip}//is; } - if ($reply =~ /^.*?\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b.*/is) { + if (!$ip) { + if ($reply =~ /^.*?\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b.*/is) { $ip = $1; - $ip = un_zero_pad($ip); + $ip = un_zero_pad($ip); $ip = filter_local($ip) if opt('fw-banlocal', $h); - } elsif ( $ip = ipv6_match($reply) ) { - $ip = un_zero_pad($ip); - $ip = filter_local($ip) if opt('fw-banlocal', $h); - } else { - warning("found neither ipv4 nor ipv6 address"); + } elsif ( $ip = ipv6_match($reply) ) { + $ip = un_zero_pad($ip); + $ip = filter_local($ip) if opt('fw-banlocal', $h); + } else { + warning("found neither ipv4 nor ipv6 address"); + } } if (($use ne 'ip') && (define($ip,'') eq '0.0.0.0')) { $ip = undef;