Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # save as 'hosts.rb'
- # put the sites you want to block in the section below __END__
- # ruby with 'sudo ruby hosts.rb'
- new_hosts = ' '+DATA.read.split("\n").join(' ')
- hosts = open('/etc/hosts') {|fh| fh.map {|s| s.chomp } }
- hosts.each_with_index {|h,i| hosts[i] = "127.0.0.1 localhost #{new_hosts}" if h =~ /^127\.0\.0\.1/ }
- print "blocking #{new_hosts}..."
- `cp /etc/hosts /etc/hosts.bak`
- open('/etc/hosts', 'w') {|fh| fh.puts(hosts) }
- puts "done."
- __END__
- foo.com
- bar.com
Add Comment
Please, Sign In to add comment