Skip to content

Instantly share code, notes, and snippets.

@Jcpetrucci
Created April 2, 2015 17:57
Show Gist options
  • Save Jcpetrucci/58dffb0cfdb7eeacc946 to your computer and use it in GitHub Desktop.
Save Jcpetrucci/58dffb0cfdb7eeacc946 to your computer and use it in GitHub Desktop.
Creates dbedit (Check Point) CLI configuration syntax out of large groups of IP address data.
#!/bin/bash
# Creates dbedit CLI configuration syntax out of large groups of IP address data.
[[ "$#" == 1 && -f "$1" ]] || { printf "First argument should be filename containing IP addresses in form of '#.#.#.#'.\n" >&2; exit 1; }
OUTFILE="$(mktemp)"
exec 3<> "$OUTFILE"
# Make group of objects just created
read -r -p "Group name (e.g. 'blacklist'): " GROUPNAME
#read -r -p "Host prefix (e.g. 'badip'): " PREFIX # Don't feel like sanitizing this at the moment. I'll just hardcode a prefix on the next line.
PREFIX="host_"
printf "create network_object_group %s\n" "$GROUPNAME" >&3
read -r -p "Host(s) comment value (e.g. CHG number): " DESCRIPTION
while FS='' read -r line; do
grep -Eq "^([0-9]+\.){3}[0-9]+$" <<<"$line" || {
printf "Line does not match expected format. Line: %s\n" "$line" >&2;
exit 1;
}
SAFENAME="${PREFIX}${line//./_}"
printf "create host_plain %s\n" "$SAFENAME" >&3
printf "modify network_objects %s ipaddr %s\n" "$SAFENAME" "$line" >&3
printf "modify network_objects %s comments \'%s\'\n" "$SAFENAME" "$DESCRIPTION" >&3
printf "update network_objects %s\n" "$SAFENAME" >&3
printf "addelement network_objects %s '' network_objects:%s\n" "$GROUPNAME" "$SAFENAME" >&3
done < "${1}"
printf "update network_objects %s\n" "$GROUPNAME" >&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