I am trying to block a range of IP address on my Ubuntu 16.04LTS server from a specific country, i.e. China, Iran, etc.
I was hoping to find a script or something I could run to easily make a dynamically updating list. As in I just put in country codes and it auto populates the current list from somewhere then appended my block range. Making it easy to updates for the list of address as they change. But to start with I used country ip blocks to find a list of addresses for China and saved them to a text file titled "chinaiprange.txt"
After some searching I found the following command to enter them all in at once from this example
while read line; do sudo ufw insert 1 deny from $line to any; done < chinaiprange.txt
However when I run it I recieve the following output:
ERROR: Bad source address
The addresses are saved in the following format:
126.96.36.199/24 188.8.131.52/23 184.108.40.206/21 ...
If there is a better way to do this that would be great but letting me know what I am doing wrong would be just as awesome. Thanks in advance!