Fix to always prefer displaying external IP address #1184

https://github.com/webmin/webmin/issues/1184#issuecomment-1446340234
This commit is contained in:
iliajie
2023-02-27 15:44:00 +02:00
parent ec6df9cf85
commit 69ccb45686

View File

@@ -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 });