There may come a time when you want to limit your http download bandwidth coz it’s taking up all your bandwidth. I came across two apps that try to accomplish this task but I am afraid to say they are too hard to understand. So let’s just do this in the terminal.
1. First, create a pipe/rule that allows 100KB/s
sudo ipfw pipe 1 config bw 100KByte/s
2. Then assign that pipe to port 80 which is the remote web server’s http port #. It’s src-port coz the data is coming into your computer.
sudo ipfw add 1 pipe 1 src-port 80
3. At this point, all your http download bandwidth will max out at 100KByte/s. You could then do other things like ssh’ing to your work place or whatever.
4. To clear the bandwidth limit, do the following to remove pipe 1.
sudo ipfw delete 1
All these can be done on the fly. No reboot nonsense.
For more info, google for “ipfw bandwidth throttle” or do a “man ipfw”.
#!/bin/bash
# by unl0cker
# Help
case “$@” in
“”)
echo “”
echo “Use fwcap -h for help.”
echo “”
exit 1
;;
*)
# Initialization of all variables
PROTO=”tpc”
TYPE=”$1″
RULE_NUMBER=”$2″
PORT=”$3″
CAP_AMOUNT=”$4″
if [ “$(id -u)” != “0” ]; then ## Check for credentials
echo “”
echo ” This script must be run as root. Use sudo or su!” 1>&2
echo “”
exit 1
fi
if [ “$1” != “-c” ]; then
if [ “$1” != “-d” ]; then
if [ “$1” != “-s” ]; then
if [ “$1” != “-h” ]; then
echo “”
echo ” Use fwcap -h for help”
fi
fi
fi
fi
if [ “$1” = “-h” ]; then
echo “”
echo ” Mac OSX Bandwidth Cap”
echo “”
echo ” Usage: fwcap [c/d/s/h] [rule#] [port#] [limit in KB]”
echo “”
echo ” Examples:”
echo “”
echo ” 1 – To create a 50KB/s cap on any connection to port 80 use: fwcap -c 2 80 50″
echo “”
echo ” 2 – To create a 200KB/s cap on any connection to port 21 use: fwcap -c 5 21 200″
echo “”
echo ” 3 – To remove rule number x: fwcap -d 2″
echo “”
echo ” 4 – To display current custom rules in use: fwcap -s”
echo “”
echo ” 5 – This help page: fwcap -s”
echo “”
fi
if [ “$TYPE” = “-c” ]; then ## Create a capped pipe and attach the port to it
echo “”
echo -e ” [*] Pipe number $RULE_NUMBER with limit of $CAP_AMOUNT KB/s created”
echo -e ” [*] Rule number $RULE_NUMBER created”
echo “”
echo -e ” Now caping port $PORT to $CAP_AMOUNT KB/s.”
echo “”
ipfw pipe 1 config bw “$CAP_AMOUNT”KB/s >/dev/null 2>&1
ipfw add $RULE_NUMBER pipe $RULE_NUMBER tcp from any $PORT to me >/dev/null 2>&1
fi
if [ $TYPE = “-d” ]; then ## Delete the rule
echo “”
echo -n “[*] Deleting rule number $RULE_NUMBER.”
ipfw delete $RULE_NUMBER >/dev/null 2>&1
echo “”
fi
if [ $TYPE = “-s” ]; then ## Show active rules
echo “”
ipfw show | sed ‘/65535/,/any/d’ | awk ‘{print ” Rule: ” $5 ; print ” Port: ” $9 ; print ” Proto: ” $6 ; print ” Source: ” $8 ; print ” Destination: ” $11 ; print “———————–“} ‘
echo “”
fi
;;
esac
#exit 1
LikeLike