Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save netravnen/6630bf498bded2074b6bae28fd909aa3 to your computer and use it in GitHub Desktop.
Save netravnen/6630bf498bded2074b6bae28fd909aa3 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
###
#
# Example input 100.64/10 -> 100.64.0.0 255.192.0.0
#
# Split into /24's -> cidr 255.255.0.0
# Split into /16's -> cidr 255.255.255.0
#
# Replace cidr with relavant value, if splitting on non-classful boundaries
#
# Note:
# Depending on if you experience the output does not output the fill list, it could
# be necessary to use a nested loop to get the relevant ranges. If the final item
# count is large enough.
#
###
for supernet in $(
ipcalc -b 100.64.0.0 255.192.0.0 255.255.0.0 |
grep -P '^Network' |
grep -P -o '(\d+\.){3}\d+\/\d+';
); do
for subnet in $(
ipcalc -b ${supernet} 255.255.0.0 255.255.255.0 |
grep -P '^Network' |
grep -P -o '(\d+\.){3}\d+\/\d+';
); do
echo $subnet;
done
done
#! /usr/bin/env bash
###
#
# Example input 100.64/10 -> 100.64.0.0 255.192.0.0
#
# Split into /24's -> cidr 255.255.0.0
# Split into /16's -> cidr 255.255.255.0
#
# Replace cidr with relavant value, if splitting on non-classful boundaries
#
###
for subnet in $(
ipcalc -b 100.64.0.0 255.192.0.0 255.255.0.0 |
grep -P '^Network' |
grep -P -o '(\d+\.){3}\d+\/\d+';
); do
echo $subnet;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment