-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #375 from smerle33/updatecli/public-db/vnet
chore(updatecli): add azure-public-db-vnet in the manifest and calcul netmask
- Loading branch information
Showing
2 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# Return netmask for a given network and CIDR. | ||
# Convert CIDR suffix to netmask | ||
cidr_to_netmask() { | ||
local cidr=$1 | ||
local mask=(0 0 0 0) | ||
for ((i=0; i<cidr; i++)); do | ||
mask[i/8]=$((mask[i/8] + (1 << (7 - i % 8)))) | ||
done | ||
echo "${mask[0]}.${mask[1]}.${mask[2]}.${mask[3]}" | ||
} | ||
# Extract IP address and CIDR suffix | ||
ip=$(cut -d'/' -f1 <<< "$1") | ||
suffix=$(cut -d'/' -f2 <<< "$1") | ||
|
||
# Convert CIDR suffix to netmask | ||
netmask=$(cidr_to_netmask "${suffix}") | ||
|
||
# echo result | ||
echo "${ip} ${netmask}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters