mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-07 11:00:36 +00:00
network: add unique_ips function
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
8286ef53bb
commit
8f75194cd8
@ -665,4 +665,24 @@ sub canonical_ip {
|
|||||||
return $ip_obj->canon();
|
return $ip_obj->canon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# List of unique, canonical IPs in the provided list.
|
||||||
|
# Keeps the original order, filtering later duplicates.
|
||||||
|
sub unique_ips {
|
||||||
|
my ($ips) = @_;
|
||||||
|
|
||||||
|
my $res = [];
|
||||||
|
my $seen = {};
|
||||||
|
|
||||||
|
for my $ip (@{$ips}) {
|
||||||
|
$ip = canonical_ip($ip);
|
||||||
|
|
||||||
|
next if $seen->{$ip};
|
||||||
|
|
||||||
|
$seen->{$ip} = 1;
|
||||||
|
push @{$res}, $ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user