Skip to content

Instantly share code, notes, and snippets.

@Jcpetrucci
Last active August 29, 2015 14:13
Show Gist options
  • Save Jcpetrucci/6418b7f36da96df119a1 to your computer and use it in GitHub Desktop.
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.
#!/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