Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2.  
  3. banHost="www.example.com"
  4.  
  5. function isRoot() {
  6. me=`id -u`
  7. root=`id -u root`
  8. if [ $me -ne $root ]; then
  9.     echo root permission required.
  10.     return 0
  11. else
  12.     return 1
  13. fi
  14. }
  15.  
  16. function on() {
  17.     cmd="ipfw -q add"
  18.     ks="keep-state"
  19.     $cmd 1 check-state
  20.     # Flush all rules
  21.     ipfw -q flush
  22.     $cmd 1 deny all from any to $banHost out setup $ks
  23. }
  24.  
  25. function off() {
  26.     cmd="ipfw -q delete"
  27.     $cmd 1
  28. }
  29.  
  30. function firewall() {
  31.  
  32.     case $1 in
  33.         'on' )
  34.         on
  35.         ;;
  36.         'off' )
  37.         off
  38.         ;;
  39.     esac
  40. }
  41.  
  42. isRoot
  43. if [ $? -eq 0 ]; then
  44.     exit
  45. else
  46.     if [ -z $1 ]; then
  47.         echo "toggle_net.sh [on | off]"
  48.         exit
  49.     fi
  50.  
  51.     firewall $1
  52. fi