Skip to content

Instantly share code, notes, and snippets.

@leonboot
Last active March 27, 2018 06:05
Show Gist options
  • Save leonboot/0ea599d5b0a27787e2a5b3e31755a574 to your computer and use it in GitHub Desktop.
Save leonboot/0ea599d5b0a27787e2a5b3e31755a574 to your computer and use it in GitHub Desktop.
Block and unblock all Facebook IP addresses on macOS (using pfctl, so it might work on BSD as well)
#!/bin/bash
( \
echo -n "table <facebook> persist { "; \
whois -h whois.radb.net '!gAS32934' | tail -n 2 | head -n 1 | sed 's/\ /,\ /g' | tr -d '\n'; \
echo -n ', '; \
whois -h whois.radb.net '!6AS32934' | tail -n 2 | head -n 1 | sed 's/\ /, /g' | tr -d '\n'; \
echo ' }'; \
echo "block quick to <facebook>" \
) | sudo pfctl -f -
sudo pfctl -E
#!/bin/bash
sudo pfctl -t facebook -T kill
sudo pfctl -F rules
@leonboot
Copy link
Author

This script looks up all IPv4 and IPv6 ranges in use by Facebook, adds them to a PF table and blocks traffic to addresses in that table. Unblocking is done by removing the table and flushing all rules, so use at your own discretion, should you have other PF rules in place!

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