#!/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 Lookup Gateway'; print ''; print ''; if ($METHOD eq 'GET') { 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.


Get information about domain/host/address:

This is all that is required for you to fill in. You can now the query, or you can have a look at the ways you can alter the query below.


DNS Server to use. By default, we will use the local nameserver.

Class of information (ignored for reverse DNS lookups):
As much information as possible (class=ANY) (default)
Mail servers for host/domain (class=MX)
List known name servers for the domain (this only makes sense for domains, eg. nccnet.co.uk) (class=NS)
Display start of authority record for the domain (this only makes sense for domains, eg. nccnet.co.uk) (class=SOA)

There are other classes beyond those those listed above, but they are either rarely used, or pointless unless listing an entire domain.

List the resuts verbosely. The format of the returned data is machine readable, and is the format used to create the DNS databases. It often returns extra information as well, on top of the original query.


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 '';