Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Throttle bandwidth to individual domains on os x

View Throttling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#!/bin/bash
# if you do not have access to run the script, run "chmod 755 throttling"
# to run enter in terminal "./throttling [speed]"
# full (no throttling)
# fast (300Kbit)
# medium (100Kbit)
# slow (10Kbit)
# wwdc (1Kbit)
# off (blocks connection)
 
# configuration
host1="yourdomain.com"
host2="localhost:3000"
 
# usage
if [ "$*" == "" ]; then
echo "usage: $0 [full|fast|medium|slow|wwdc|off]"
exit
fi
 
# remove any previous firewall rules
sudo ipfw list 100 > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo ipfw delete 100 > /dev/null 2>&1
fi
sudo ipfw list 110 > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo ipfw delete 110 > /dev/null 2>&1
fi
sudo ipfw list 200 > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo ipfw delete 200 > /dev/null 2>&1
fi
sudo ipfw list 210 > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo ipfw delete 210 > /dev/null 2>&1
fi
 
# process the command line option
if [ "$1" == "full" ]; then
echo "full speed"
elif [ "$1" == "off" ]; then
# add rules to deny any connections to configured host
if [ -n "$host1" ]; then
sudo ipfw add 100 deny tcp from $host1 to me
sudo ipfw add 110 deny tcp from me to $host1
fi
if [ -n "$host2" ]; then
sudo ipfw add 200 deny tcp from $host2 to me
sudo ipfw add 210 deny tcp from me to $host2
fi
else
# create a pipe with limited bandwidth
bandwidth="100Kbit"
if [ "$1" == "fast" ]; then
bandwidth="300Kbit"
elif [ "$1" == "slow" ]; then
bandwidth="10Kbit"
elif [ "$1" == "wwdc" ]; then
bandwidth="1Kbit"
fi
sudo ipfw pipe 1 config bw $bandwidth
 
# add rules to use bandwidth limited pipe
if [ -n "$host1" ]; then
sudo ipfw add 100 pipe 1 tcp from $host1 to me
sudo ipfw add 110 pipe 1 tcp from me to $host1
fi
if [ -n "$host2" ]; then
sudo ipfw add 200 pipe 1 tcp from $host2 to me
sudo ipfw add 210 pipe 1 tcp from me to $host2
fi
fi
 
sudo ipfw list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.