#!/usr/bin/perl -wT
##############################################################################
##
## DNS Lookup CGI
##
## Copyright (C) 1998 Chris Johnson (sixie@nccnet.co.uk)
##
##############################################################################
##
## This is an all in one thing...no seperate HTML page needed!! Just place
## this in your cgi-bin directory and your away :-)
##
#############################################################################
use vars '$METHOD';
require '/home/chris/www/cgi/six-cgi.pl';
&print_header;
&init_cgi;
print '';
print '
';
print 'DNS Host Lookups
When you enter the name of a computer on the internet, for
example, www.nccnet.co.uk or www.yahoo.com,
your computer needs to translate the name into a form it can
understand. This is where the Domain Name System (DNS) steps
in. The job of DNS is to translate between a host name and the
host address.
For example, a query may say "what is the address of
www.nccnet.co.uk?". The response from a DNS server,
(a machine that is able to carry out the queries), will say
"www.nccnet.co.uk has address 195.188.44.1".
Another query type is the reverse lookup. This is when
a computer may say "I have the address 195.188.44.1.
What is the hostname of this address?". Occasionaly, a reverse
DNS lookup will fail, as it is not mandatory for every host on
the Internet to have a name, or the name server for a
particular domain may not be accessible at the time.
This page will allow you to interrogate a DNS server, and
allow you to get various information about a specific host.
EOF
;
} else {
$err = 0;
$server=$FORM{server};
$domain=$FORM{host};
$class=$FORM{class};
$verbose=$FORM{verbose};
local ($oldbar) = $|;
$cfh = select (STDOUT);
$| = 1;
print 'DNS/Host Lookup
';
$server =~ s/ *//g;
$domain =~ s/ *//g;
if ($server eq '') {
print 'Server address/name cannot be empty
';
$err=1;
}
if ($domain eq '') {
print 'Domain address/name cannot be empty
';
$err=1;
}
if ($server =~ /^([A-Za-z0-9.-]+)$/) {
$server = $1;
} else {
print "Server address/name ($server) contains illegal characters
";
$err=1;
}
if ($domain =~ /^([A-Za-z0-9.-]+)$/) {
$domain = $1;
} else {
print "Domain address/name ($domain) contains illegal characters
";
$err=1;
}
if ($class =~ /^([a-z]+)$/) {
$class = $1;
} else {
print "Class is tainted
";
$err=1;
}
if ($verbose =~ /^(-v)$/) {
$verbose = $1;
} else {
print "Verbose flag is tainted
";
$err=1;
}
if ($err == 0) {
$ENV{'PATH'} = '/bin:/usr/bin';
print "Looking up information for $domain...
\n";
print "(Running command: host -t $class $verbose $domain $server)
\n";
print '';
$| = $oldbar;
select ($cfh);
system ("/usr/bin/host -t $class $verbose $domain $server 2>&1");
wait();
print '';
} else {
print '
Errors have been detected on the form input. ';
print 'Please rectify and try again.';
}
}
print '
';
print 'This CGI by CEJ/Sixie, Tuesday 9th June 1998';
print '';
print '';