#!/usr/local/bin/perl # Author: TL Guan (GuTi) - guantl@gmail.com # Last Mod: 25 April 2008 # # domain-filter.pl - grab the domains from the domains.txt file # which is downloaded from malwaredomains.com # and put in a file for dns blacklist. # # Usage: perl domain-filter.pl readfile writefile # # readfile - domains.txt from malwaredomains.com # writefile - dns_blacklist.txt # ############################################### use strict; my $argc = $#ARGV+1; if ($argc != 2) { print "Usage: perl domain-filter.pl [readfile] [writefile]\n"; exit(1); } my $read = $ARGV[0]; chomp( $read ); my $write = $ARGV[1]; chomp( $write ); process( $read, $write ); exit(0); sub process { my $readfile = $_[0]; my $writefile = $_[1]; open (READFILE, "$readfile") || die ("ERROR: $!\n"); open (WRITEFILE, ">$writefile"); while (my $data = ) { chomp( $data ); if ($data =~ m/^\#/) { next; } elsif ($data =~ m/(\w+(\-+)?\.?)+\w+\.?\w+/) { my $bl_domain = $&; chomp( $bl_domain ); print WRITEFILE "$bl_domain A\n"; } } close (WRITEFILE); close (READFILE); }