Created
July 2, 2014 14:38
-
-
Save iwakura/62376c800eddc8aa414e to your computer and use it in GitHub Desktop.
blocking ads using unbound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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