Skip to content

Instantly share code, notes, and snippets.

@j-manu
Created November 30, 2011 14:18
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-manu/1409218 to your computer and use it in GitHub Desktop.
Save j-manu/1409218 to your computer and use it in GitHub Desktop.
#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
usage=$(
cat <<EOF
$0 [OPTIONS] start/stop
-s set speed default 256Kbit/s
-p set port default 3000
-d set delay default 350ms
EOF
)
PORT="3000"
DELAY="350ms"
SPEED="256Kbit/s"
while getopts ":s:p:d:" opt ; do
case $opt in
s)
SPEED="$OPTARG"
;;
p)
PORT="$OPTARG"
;;
d)
DELAY="$OPTARG"
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
\?)
echo ""
echo "$usage"
exit 0
;;
esac
done
# Makes the argument after all the options $1
shift $(($OPTIND - 1))
if [ "$1" != 'start' ] && [ "$1" != 'stop' ] ; then
echo "$usage"
exit 0
fi
if [ $1 = "start" ]; then
echo "- Throttling $PORT to $SPEED with delay $DELAY"
sudo ipfw pipe 1 config bw $SPEED delay $DELAY
sudo ipfw add 100 pipe 1 src-port $PORT
exit 0
fi
if [ $1 = "stop" ]; then
echo "- Back to normal"
sudo ipfw delete 100
sudo ipfw pipe 1 delete
exit 0
fi
@hemikak
Copy link

hemikak commented Oct 20, 2015

For MAC OS X, this code is now outdated. The "ipfw" command is no longer in os x from yosemite onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment