From 69ccb45686205cb2df53f00aa5761717de92efa1 Mon Sep 17 00:00:00 2001 From: iliajie Date: Mon, 27 Feb 2023 15:44:00 +0200 Subject: [PATCH] Fix to always prefer displaying external IP address #1184 https://github.com/webmin/webmin/issues/1184#issuecomment-1446340234 --- system-status/system_info.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/system-status/system_info.pl b/system-status/system_info.pl index eaee67dcc..0333e5da7 100644 --- a/system-status/system_info.pl +++ b/system-status/system_info.pl @@ -35,9 +35,16 @@ push(@rv, $table); if (&show_section('host')) { # Hostname - my $ip = $info && $info->{'ips'} ? $info->{'ips'}->[0]->[0] - : &to_ipaddress(get_system_hostname()); - $ip = $ip ? " ($ip)" : ""; + my @ips_all = &to_ipaddress(get_system_hostname()); + my (@ips_noloop, @ips_noloc, $ip_detect); + if (@ips_all) { + @ips_noloop = grep { $_ !~ /^127\./} @ips_all; + @ips_noloc = grep { $_ !~ /^(10\.|192\.168\.)/} @ips_noloop; + $ip_detect = @ips_noloc ? $ips_noloc[0] : + @ips_noloop ? $ips_noloop[0] : $ips_all[0]; + } + my $ip = $info && $info->{'ips'} ? $info->{'ips'}->[0]->[0] : $ip_detect; + $ip = " ($ip)" if ($ip); push(@table, { 'desc' => $text{'right_host'}, 'value' => &get_system_hostname().$ip });