sudo /bin/bash -c "iptables -A OUTPUT -d www.example.com -j DROP; echo 'iptables -D OUTPUT -d www.example.com -j DROP' | at 'now + 3 min'"Which is probably how SelfControl does it minus the pretty interface. Add a DROP rule to the firewall, and add an 'at' job to delete the DROP rule after a specified time. The firewall rule should survive reboot (it's usually saved on shutdown and restored on boot), and the 'at' job should survive until it's executed. The whitelist or protocol based stuff just gets a bit more complicated, say making a sub-chain on the OUTPUT that drops all port 80 traffic and inserting an ALLOW rule for a particular site. You can read up on the IPTables and come up with something that suits your needs maybe.
#!/bin/bash PORTS="80 443" UNDO= for p in $PORTS do iptables -I OUTPUT -p tcp --dport $p -j DROP UNDO="$UNDO iptables -D OUTPUT -p tcp --dport $p -j DROP;" done echo $UNDO | at now + 1 minThen make the program executable
posted by chrisamiller at 9:21 AM on July 27, 2010