Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'even simpler.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
even simpler.
Authored by: SOX on Jan 11, '07 04:47:11PM

you can also set up a cron job to toggle your
/etc/hosts.allow
flie to be blank and your hosts.deny file to
ALL : ALL

Alternatively if there are simply specific websites you want to prevent youself from going to you can instead add these to your hosts file like this
127.0.0.1 apple.slashdot.org slashdot.org macoshints.org nytimes.org

this will map those servers to your loopback address effectively blocking them.
if you make your ~/sites/index.html be
<H1>Get back to Work</H1>
it's even more effective



[ Reply to This | # ]
not as simple as I am!
Authored by: DotDotComma on Jan 12, '07 02:32:13AM

As in the hint at top, I've been doing a similar time-switching of half the home network to control net access for some time, but this 'cron' approach sounds perfect to tailor it a little more to individual users ...

Could you, o clever one, point me - less-clever one! - to some brief outlines on creating a cron setup to achieve this (can't even find my hosts file .... doh!)

Many thanks ....



[ Reply to This | # ]
not as simple as I am!
Authored by: SOX on Jan 12, '07 07:34:56AM
Okay i'll help you, but rather than give you the answer I'll help lead you through it.

First cron is a fairly easy syntax and the global root cron is located in /etc/crontab and it has a man page for it's syntax. (There's also user level crons in /var/crontab). But the modern way is now to use launchDeamon which has a more complex syntax that is both self documenting and a little intimidating. TO see how to do this look in
cat /System/Library/LaunchDaemons/com.apple.periodic-daily.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.periodic-daily</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/periodic</string>
<string>daily</string>
</array>
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>1</integer>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>15</integer>
</dict>
</dict>
</plist>

So you just copy this twice, make one called blocker.plist and one called unblocker.plist

in blocker,plist
change the program arguments array to
<string>/usr/local/bin/waxon_off.pl </string>
<string>off</string>
change the time to
<key>Hour</key>
<integer>8</integer>

in unblocker set things to

change the program arguments array to
<string>/usr/local/bin/waxon_off.pl </string>
<string>on</string>
change the time to
<key>Hour</key>
<integer>17</integer>

Now we need to create waxon and waxoff

copy and paste the following into a terminal
cat >/usr/local/bin/waxon_off.pl
/usr/bin/perl -w
open FH, "/etc/hosts.orig";
@S = <FH>;
close FH;
open FH, "/etc/hosts";
print FH, @S,"\n";
if (@ARGV[0] eq "off") {
print FH<<EOF;
127.0.0.1 slashdot.org apple.slashdot.org
127.0.0.1 macosxhints.com
EOF
close FH;
}

Then execute:
sudo cp /etc/hosts /etc/host.orig
chmod a+x /usr/local/bin/waxon_off.pl


There. now you will turn things off at 8 am and turn things back on at 5 pm

if you want to revert this remove the plist file and then restore the original hosts file like this.

sudo cp /etc/hosts.orig /etc/host

if you want to override it manually use
/usr/local/bin/waxon_off.pl off

edit the segment
print FH<<EOF;
127.0.0.1 slashdot.org apple.slashdot.org
127.0.0.1 macosxhints.com
EOF

to include whatever sites you want blocked.






[ Reply to This | # ]
typo fix
Authored by: SOX on Jan 12, '07 10:26:52AM

copy and paste the following into a terminal
cat >/usr/local/bin/waxon_off.pl
#!/usr/bin/perl -w # typo fix
open FH, "/etc/hosts.orig";
@S = <FH>;
close FH;
open FH, ">/etc/hosts"; # fixed a typo
print FH, @S,"\n";
if (@ARGV[0] eq "off") {
print FH<<EOF;
127.0.0.1 slashdot.org apple.slashdot.org
127.0.0.1 macosxhints.com
EOF
close FH;
}



[ Reply to This | # ]
typo fix again
Authored by: SOX on Jan 12, '07 03:28:58PM

copy and paste the following into a terminal
cat >/usr/local/bin/waxon_off.pl
#!/usr/bin/perl -w # typo fix
open FH, "/etc/hosts.orig";
@S = <FH>;
close FH;
open FH, ">/etc/hosts"; # fixed a typo
print FH, @S,"\n";
if ($ARGV[0] eq "off") {
print FH<<EOF;
127.0.0.1 slashdot.org apple.slashdot.org
127.0.0.1 macosxhints.com
EOF
close FH;
}



[ Reply to This | # ]
typo fix again
Authored by: eaglemoon on Jan 19, '07 06:54:34PM

Hi,

Thanks for the hints!

Two questions:

1)Can this also block email traffic? I don't want any internet period!

2)Is there a way to create a little application that would do this from a GUI?

I am new on the Mac - would be happy to figure out a way to do this!



[ Reply to This | # ]