Skip to content

Instantly share code, notes, and snippets.

@jgdavey
Created May 14, 2012 21:03
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgdavey/2696974 to your computer and use it in GitHub Desktop.
Save jgdavey/2696974 to your computer and use it in GitHub Desktop.
Simulate network latency and packet loss on Mac OS X (requires sudo)
#!/bin/bash
set -e
USAGE="Usage: $0 [ip_address | reset]"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
ip=$1
if [ "$ip" = "reset" ]; then
printf 'Resetting... '
sudo ipfw list | grep 'pipe' | awk '{print $1}' | while read name; do sudo ipfw delete $name ; done
echo 'Done'
else
echo "Creating rules to simulate latency to $ip... "
# Create 2 pipes and assigned traffic to and from our webserver to each:
sudo ipfw add pipe 1 ip from any to $ip
sudo ipfw add pipe 2 ip from $ip to any
# Configure the pipes we just created:
sudo ipfw pipe 1 config delay 250ms bw 1Mbit/s plr 0.1
sudo ipfw pipe 2 config delay 250ms bw 1Mbit/s plr 0.1
echo "Done"
fi
@devinwhalen
Copy link

Do you have a script for mac sierra? ipfw is no longer installed.

Thanks

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