Wednesday, October 10, 2007

Kill browser ads with Cisco router's DNS server

As you might already know, you can use the /etc/hosts file (or its Windows equivalent) to kill unwanted browser ads - just list all the banner-serving sites in you hosts file and set their IP addresses to 127.0.0.1. In my June IP Corner article, Cisco Router: the Swiss Army Knife of Network Services (section Stop the browser ads and banners), I'm describing how you can do the same thing network-wide with a router acting as a DNS server.
For those of you who would like to automate this approach and convert a hosts file into a router configuration, here's a short PERL script to do it:
#
# hostsToCisco.pl: converts hosts file into router configuration
#
# Stdin: hosts file
# Stdout: IOS configuration
#
our @line,$i;

while (<>) {
@line = split(/\s+/,$_);
next unless $line[0] eq "127.0.0.1";
for ($i = 1; $i < $#line; $i++) {
last if $line[$i] =~ /\#/;
print "ip host $line[$i] 127.0.0.1\n"
}
}

No comments:

Toplist