filter_ip.sh 476 B

12345678910111213141516171819202122232425
  1. #!/bin/sh
  2. startstop=$1
  3. if [ -z "$startstop" ]; then
  4. startstop="start"
  5. fi
  6. table="OUTPUT"
  7. ipsrc=$(cat ./ip.txt)
  8. case "$startstop" in
  9. start)
  10. for i in $ipsrc; do
  11. iptables -I ${table} -d $i -m comment --comment "ipfiltering" -j DROP
  12. done
  13. ;;
  14. stop)
  15. ipdel=$(iptables -S ${table} |grep ipfiltering|sed -e 's/\ /\n/g'|grep \\-d -A 1 |grep \\.|cut -d/ -f1)
  16. for i in $ipdel; do
  17. iptables -D ${table} -d $i -m comment --comment "ipfiltering" -j DROP
  18. done
  19. ;;
  20. esac