-
-
Save BlackDex/32c96879a5c0b7b819ea to your computer and use it in GitHub Desktop.
DNS blacklist updater to host format.
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
<?php | |
$a = new adsblock(); | |
$a->run(); | |
class adsblock { | |
public $output_hosts_file = "/etc/powerdns/hosts-ads"; | |
public $redirect_ip = "0.0.0.0"; | |
public $fileUrls = array( | |
'https://adaway.org/hosts.txt', | |
'http://adblock.gjtech.net/?format=unix-hosts', | |
'http://hosts-file.net/ad_servers.txt', | |
'http://www.malwaredomainlist.com/hostslist/hosts.txt', | |
'http://pgl.yoyo.org/adservers/serverlist.php?', | |
'http://someonewhocares.org/hosts/hosts', | |
'http://winhelp2002.mvps.org/hosts.txt', | |
); | |
public $domains = array(); | |
public function run() { | |
$this->getFiles(); | |
$this->shuffle(); | |
$this->generateHosts(); | |
} | |
private function getFiles() { | |
$data = array(); | |
foreach ($this->fileUrls as $url) { | |
$data[] = file_get_contents($url); | |
} | |
$this->rawdata = $data; | |
} | |
private function shuffle() { | |
foreach ($this->rawdata as $value) { | |
$tmp = explode("\n",$value); | |
foreach ($tmp as $k=>$value) { | |
$v = trim($value); | |
if (preg_match("/^#/",$v)) { continue; } | |
$b = preg_split("/\s/",$v); | |
if (count($b) >= 2) { | |
if (isset($b[0]) && isset($b[1])) { | |
if (!in_array($b[1],$this->domains)) { | |
$this->domains[] = $b[1]; | |
} | |
} | |
} | |
} | |
} | |
} | |
private function generateHosts() { | |
$tmp = ""; | |
foreach ($this->domains as $domain) { | |
$tmp .= sprintf("%s %s\n",$this->redirect_ip, $domain); | |
} | |
file_put_contents($this->output_hosts_file, $tmp); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment