Skip to content

Instantly share code, notes, and snippets.

@bspavel
Last active February 28, 2019 12:34
Show Gist options
  • Save bspavel/b16e8b10a41ce22717d1e6e3c5b62e6f to your computer and use it in GitHub Desktop.
Save bspavel/b16e8b10a41ce22717d1e6e3c5b62e6f to your computer and use it in GitHub Desktop.
a ipset rule generator from a file
read -p "Input file name: [default: in.txt]:" fileIn
fileIn=${fileIn:-in.txt}
echo $fileIn
read -p "Output file name: [default: block.conf]:" fileOut
fileOut=${fileOut:-block.conf}
echo $fileOut
read -p "Rule name: [default: block]:" ruleName
ruleName=${ruleName:-block}
echo $ruleName
#cp -vi $fileIn $fileOut
tr -d $'\r' < $fileIn > $fileOut
sed -i '/^#/d;/^$/d' $fileOut
sed -i '/#/d' $fileOut
sed -i 's/0.0.0.0\t//g' $fileOut
sed -i 's/127.0.0.1\t//g' $fileOut
sed -i 's/0.0.0.0 //g' $fileOut
sed -i 's/127.0.0.1 //g' $fileOut
sed -i "s/.*/ipset=\/&\/$ruleName/" $fileOut
read -p "Do you want to read the $fileOut file? <y/N> " prompt
if [ "$prompt" = "y" ]; then
less $fileOut
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment