Skip to content

Instantly share code, notes, and snippets.

@timothycarambat
Created February 11, 2019 01:28
Show Gist options
  • Save timothycarambat/b63df6489fb7d47f69af9be70fbd2972 to your computer and use it in GitHub Desktop.
Save timothycarambat/b63df6489fb7d47f69af9be70fbd2972 to your computer and use it in GitHub Desktop.
File that takes in a file of IP addresses with CIDR blocks. It then creates a new config file based on the specification. For r/programming_request https://www.reddit.com/r/programmingrequests/comments/aorj14/script_to_enter_contents_of_text_file_into/
#!/usr/bin/env bash
# This file takes in one argument (the absolute path of the generate NETFLIX file with IPs)
filename=$1
if [ -z $filename ]
then
echo "No Filename specified! Exited."
exit
fi
echo "Looking for file ${filename}"
ip_addrs=
ip_addrs_no_mask=
mapfile -t ip_addrs < $filename
for ip in "${ip_addrs[@]}"
do
fixed_ip=$( echo "$ip" | cut -f1 -d"/")
ip_addrs_no_mask+=$(echo "${fixed_ip} ")
done
newfile="new_config"
cat <<EOM > $newfile
option interface 'wan'
option comment 'Domains'
option remote_addresses '${ip_addrs_no_mask}'
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment