filter_mac.sh 584 B

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. startstop=$1
  3. if [ -z "$startstop" ]; then
  4. startstop="start"
  5. fi
  6. table="forwarding_lan_rule"
  7. filtertable="forwarding_lan_rules_kids"
  8. macsrc=$(cat ./mac.txt)
  9. case "$startstop" in
  10. start)
  11. for i in $macsrc; do
  12. iptables -I ${table} -m mac --mac-source $i -m comment --comment "macfiltering" -j ${filtertable}
  13. done
  14. ;;
  15. stop)
  16. macdel=$(iptables -S ${table} |grep macfiltering|sed -e 's/\ /\n/g'|grep mac-source -A 1 |grep :)
  17. for i in $macdel; do
  18. iptables -D ${table} -m mac --mac-source $i -m comment --comment "macfiltering" -j ${filtertable}
  19. done
  20. ;;
  21. esac