ip_block/other/toggle_block

44 lines
777 B
Plaintext
Raw Normal View History

2023-06-14 15:56:42 +00:00
#!/bin/bash
if [ ! -z $@ ]
then
echo "Checking Current Block State"
NUM=`iptables -L --line-numbers | grep 'usa_state' | head -n 1 | cut -c1`
echo
echo "/----------------------------\\"
if [ -z "$NUM" ]
then
echo "| iptable Rule Disabled |"
else
echo "| iptables Rule Enabled |"
fi
echo "\\----------------------------/"
exit 0
fi
echo "Checking Current Block State"
NUM=$(iptables -L --line-numbers | grep 'usa_state' | head -n 1 |cut -c1)
if [ -z "$NUM" ]
then
echo "Enabling iptables Rule"
sudo iptables -A INPUT -m set ! --match-set usa_state src -j DROP &>/dev/null
else
echo "Disabling iptables Rule"
sudo iptables -D INPUT $NUM &>/dev/null
fi
if [ $? -eq 0 ]
then
echo "Success"
exit 0
else
echo "Error"
exit 1
fi