From 55e6485bf323fb055d111a224dbd0dc71b4a55bf Mon Sep 17 00:00:00 2001 From: fanta Date: Fri, 25 Feb 2022 17:55:22 +0100 Subject: [PATCH] =?UTF-8?q?primera=20versi=C3=B3n=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruBlock.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 ruBlock.sh diff --git a/ruBlock.sh b/ruBlock.sh new file mode 100755 index 0000000..9174014 --- /dev/null +++ b/ruBlock.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# fanta +# ru block +# dependencies: bash wget + +ipListUrl="https://www.ipdeny.com/ipblocks/data/countries/ru.zone" + +function main(){ + checkURL + downloadIPList + blockIP +} + +function checkURL(){ + errorCode=$(curl -kiss $ipListUrl | head -1 | cut -d " " -f 2) + if [ $errorCode != 200 ]; then echo "URL not found $ipListUrl"; exit; fi +} + +function downloadIPList(){ + wget -q "$ipListUrl" -O /tmp/.ips > /dev/null 2>&1 +} + +function blockIP(){ + while read -r ip; do echo "DROP $ip"; iptables -A INPUT -s $ip -j DROP; done < /tmp/.ips +} + +main