#!/usr/bin/perl -w # require 5; use strict; my ($Address, $Hostname, $is_valid_address) = ($ENV{'QUERY_STRING'}, '', 0); $Address =~ s!\Aaddr=!!; if ($Address) { if ($Address =~ m!(\d+)\.(\d+)\.(\d+)\.(\d+)!) { $is_valid_address = 1; $Hostname = (gethostbyaddr(pack('C4', $1, $2, $3, $4), 2))[0]; $Hostname = 'no reverse DNS for this IP' unless $Hostname; } else { $Hostname = 'Query string does not pattern match to dd.dd.dd.dd'; } } print <<"EOM"; Content-Type: text/html <HTML> <HEAD> <TITLE>nslookup $Address</TITLE> <META NAME="description" CONTENT="Simple form for resolving IP addresses into DNS names."> <link rel="stylesheet" href="../w1wc.css" type="text/css"> EOM if (open(FILE, "<../header.txt")) { while (<FILE>) { print; } close(FILE); } print <<"EOM"; <p><table width="675" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width=675 height=90> <param name=movie value="../flash_files/w1wc_header_pages.swf"> <param name=quality value=high> <param name=bgcolor value=#000066> <embed src="../flash_files/w1wc_header_pages.swf" quality=high bgcolor=#000066 width=675 height=90 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> </embed> </object></td> </tr> </table></p><br> <P>&nbsp;</P><P>&nbsp;</P><P>&nbsp;</P> <HR SIZE=1><SPAN> <B>[</B> <A HREF="http://www.w1wc.com/">Main Page</A> <B>|</B> <A HREF="http://www.w1wc.com/wwwboard/wwwboard.html">Discussion Forum</A> <B>|</B> <A HREF="$ENV{'SCRIPT_NAME'}">Name Lookup</A> <B>]</B> </SPAN><HR SIZE=1> <P><BR></P> <FORM METHOD="get" ACTION="$ENV{'SCRIPT_NAME'}"> <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0> <TR> <TD ALIGN=right>IP Address: &nbsp;</TD> <TD>$Address</TD> </TR><TR> <TD ALIGN=right>Hostname: &nbsp;</TD> <TD>$Hostname</TD> </TR><TR> <TD COLSPAN=2><BR></TD> </TR><TR> <TD ALIGN=right>IP Address: &nbsp;</TD> <TD><INPUT TYPE="text" NAME="addr"> <INPUT TYPE="submit" VALUE="Lookup Name" STYLE="background-color:#ffffff;cursor:hand"></TD> </TR><TR> <TD ALIGN=right>Example: &nbsp;</TD> <TD><A HREF="$ENV{'SCRIPT_NAME'}?addr=198.137.240.92">198.137.240.92</A></TD> </TR> </TABLE> </FORM> EOM # Thanks to Grant M of BostonHot.com for this idea: print <<"EOM" if ($is_valid_address); <P>The <A HREF="http://www.arin.net/cgi-bin/whois.pl?queryinput=$Address"><b>ARIN system</b></A> will tell you which organization has been assigned this block of IP addresses. This is useful when the name lookup fails.</P> EOM print <<"EOM"; <P>The <A HREF="/name_lookup.txt">source code</A> for the script is available.</P> <P><BR></P> <HR SIZE=1><SPAN> <B>[</B> <A HREF="http://www.w1wc.com">Main Page</A> <B>|</B> <A HREF="http://www.w1wc.com/wwwboard/wwwboard.html">Discussion Forum</A> <B>|</B> <A HREF="$ENV{'SCRIPT_NAME'}">Name Lookup</A> <B>]</B> </SPAN><HR SIZE=1> EOM if (open(FILE, "<../footer.txt")) { while (<FILE>) { print; } close(FILE); }