#!/bin/bash # configuration host="twitter.com" # usage if [ "$*" == "" ]; then echo "usage: $0 [off|fast|medium|slow]" exit fi # remove any previous firewall rules sudo ipfw list 10 > /dev/null 2>&1 if [ $? -eq 0 ]; then sudo ipfw delete 10 > /dev/null 2>&1 fi sudo ipfw list 11 > /dev/null 2>&1 if [ $? -eq 0 ]; then sudo ipfw delete 11 > /dev/null 2>&1 fi # process the command line option if [ "$1" == "off" ]; then # add rules to deny any connections to configured host sudo ipfw add 10 deny tcp from $host to me sudo ipfw add 11 deny tcp from me to $host else # create a pipe with limited bandwidth bandwidth="100Kbit" if [ "$1" == "fast" ]; then bandwidth="300Kbit" elif [ "$1" == "slow" ]; then bandwidth="10Kbit" fi sudo ipfw pipe 1 config bw $bandwidth # add rules to use bandwidth limited pipe sudo ipfw add 10 pipe 1 tcp from $host to me sudo ipfw add 11 pipe 1 tcp from me to $host fi