Skip to content

Instantly share code, notes, and snippets.

@iwakura
Created July 2, 2014 14:38
Show Gist options
  • Save iwakura/62376c800eddc8aa414e to your computer and use it in GitHub Desktop.
Save iwakura/62376c800eddc8aa414e to your computer and use it in GitHub Desktop.
blocking ads using unbound
#!/usr/bin/env ruby
# script generates fake zones to plug into unbound in order to block some ads sites.
require 'open-uri'
class FakeZoneGenerator
LIST_URL = 'http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml&showintro=0'
IPV4_ADDR = '127.0.0.1'
IPV6_ADDR = '::1'
def self.generate
list = open(LIST_URL).read
conf = []
list.each_line do |line|
host = line.strip
conf << %{local-zone: "#{host}" redirect}
conf << %{local-data: "#{host} A #{IPV4_ADDR}"}
conf << %{local-data: "#{host} AAAA #{IPV6_ADDR}"}
end
conf.join("\n")
end
end
if $0 == __FILE__
puts FakeZoneGenerator.generate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment