I can't quite remember why, but I wrote this script as a proof of concept. It allows you to set your DNS servers based on the user executing some program, command line arguments, the time of day, or anything else your heart may desire. It's pretty nasty, but it could be useful if you can't be bothered setting up a suitably complicated DNS server, you want to redirect one program to use another resolver (for analysing one that 'phones home' for instance, though I can't think why you wouldn't just use /etc/hosts/
.
Okay, I admit that it doesn't have many plausible uses. Maybe you want to confuse someone on a multi-user system by redirecting their browser to shock sites, but when they run cat
on resolv.conf, it shows up something normal.
#!/usr/bin/perl -w $FIFO="/etc/resolv.conf"; while (1) { unless (-p $FIFO) { unlink $FIFO; system('mknod', $FIFO, 'p') && die "Can't mknod $FIFO: $!"; } open (FIFO, "> $FIFO") || die "Can't write $FIFO: $!"; my $foo = `lsof -n | grep resolv.conf | grep -v $$`; @stuff = split(/\s+/, $foo); my $pid = $stuff[1]; my $cmdline = `cat /proc/$pid/cmdline`; if ($cmdline =~ /\.casa/ ) { print FIFO "nameserver 10.0.0.37\n"; } elsif ($stuff[2] eq "jaq") { print FIFO "nameserver 2.2.2.2\n"; } else { print FIFO "nameserver 202.174.32.6\n"; } # debug: print $cmdline . " - " . $stuff[2] . "\n"; close FIFO; sleep 1; }