Last active
August 29, 2015 14:13
-
-
Save Jcpetrucci/6418b7f36da96df119a1 to your computer and use it in GitHub Desktop.
Creates PAN-OS CLI configuration syntax out of large groups of IP/NETMASK data.
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
#!/bin/bash | |
# Creates PAN-OS CLI configuration syntax out of large groups of IP/NETMASK data. | |
[[ "$#" == 1 && -f "$1" ]] || { printf "First argument should be filename containing networks in form of '#.#.#.#/#'.\n" >&2; exit 1; } | |
OUTFILE="$(mktemp)" | |
exec 3<> "$OUTFILE" | |
read -r -p "Address description value (e.g. CHG number): " DESCRIPTION | |
while FS='' read -r line; do | |
grep -Eq "([0-9]+\.){3}[0-9]+/[0-9]+" <<<"$line" || { | |
printf "Line does not match expected format. Line: %s\n" "$line" >&2; | |
exit 1; | |
} | |
SAFENAME="${line//\//_}" | |
ADDRESSES=(${ADDRESSES[@]} $SAFENAME) | |
printf "set address %s description \"%s\" ip-netmask %s\n" "$SAFENAME" "$DESCRIPTION" "$line" >&3 | |
done < "${1}" | |
# Make group of objects just created | |
read -r -p "Address group name: " | |
printf "set address-group \"%s\" description \"%s\" static [ %s ]\n" "$REPLY" "$DESCRIPTION" "${ADDRESSES[*]}" >&3 | |
# Create the output | |
exec 3>&- | |
cat "$OUTFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment