group ip address to different subnet with shell
0
votes
1
answer
125
views
Actually, this is for a redis cluster, I have 3 master ips and 3 slave ips, need to produce 3 pairs of IP addresses where the addresses in the pair are in different /24 subnets.
Or in other words, given a list of
n
IP addresses (n
being an even number, and not more than half of the IP addresses being in the same /24
subnet), how to partition them into n
/2 pairs where the two addresses in each pair are in different /24 subnets?
The pairs should be stored as key and values of an ip_map
associative array. For example, given a list of IP addresses stored in a $ips
array:
ips=(
"172.211.91.63"
"172.211.90.61"
"172.211.91.30"
"172.211.90.173"
"172.211.89.233"
"172.211.89.166"
)
The result could be:
declare -A ip_map=(
[172.211.91.63]=172.211.90.61
[172.211.91.30]=172.211.89.233
[172.211.90.173]=172.211.89.166
)
Asked by peng xiao
(59 rep)
Oct 8, 2024, 06:12 AM
Last activity: Oct 9, 2024, 12:45 PM
Last activity: Oct 9, 2024, 12:45 PM