Created
May 14, 2012 21:03
-
-
Save jgdavey/2696974 to your computer and use it in GitHub Desktop.
Simulate network latency and packet loss on Mac OS X (requires sudo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have a script for mac sierra? ipfw is no longer installed.
Thanks