|
A collection of useful facts by Joel Williams. Adelaide denizen. Computer tinkerer. Former terrestrial ecology student of Flinders University. PhD candidate at ANU. Editor for freshmeat.net. Adelaide University Mountain Club member and outdoor enthusiast. Occasional networking go-to guy. Contact me by email at joel at this domain. |
Magic Resolv ConfI 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 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 #!/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;
}
|