Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # save as 'hosts.rb'
  4. # put the sites you want to block in the section below __END__
  5. # ruby with 'sudo ruby hosts.rb'
  6.  
  7. new_hosts = ' '+DATA.read.split("\n").join(' ')
  8. hosts = open('/etc/hosts') {|fh| fh.map {|s| s.chomp } }
  9. hosts.each_with_index {|h,i| hosts[i] = "127.0.0.1 localhost #{new_hosts}" if h =~ /^127\.0\.0\.1/ }
  10. print "blocking #{new_hosts}..."
  11. `cp /etc/hosts /etc/hosts.bak`
  12. open('/etc/hosts', 'w') {|fh| fh.puts(hosts) }
  13. puts "done."
  14.  
  15. __END__
  16. foo.com
  17. bar.com
Add Comment
Please, Sign In to add comment