This takes an input of a machine name or an IP address, and checks to see if it exists and presents the name resolution. I included the script and the HTML page.

The coolest part of this (for me) was getting the name resolution down to one line. I couldn't have put this togther without bastardoperator and the other monks...

use CGI qw(:standard); print header(); print start_html('Resolved'); &resolve(); print param('xinput')." resolved to $new"; print end_html; #To resolve host names (xname) or IP(xip)... sub resolve{ if (param('xinput')=~/^\D/){ # if begins with a letter assume it's + a name $new=join('.',(unpack("C4", gethostbyname(param('xinput'))))); }elsif (param('xinput')=~/^\d/){ # if begins with a number assume +it's an IP $new=gethostbyaddr(pack("C4", (split(/\./, param('xinput')))), + AF_INET); } if (($new eq null)||($new eq "")){ print "Could not resolve.\n"; die "Could not resolve.\n"; } } print "<p><a href=".referer().'>back</a></p>';
Resolver.htm
<HTML> <HEAD> <TITLE>Name Resolution</TITLE> </HEAD> <BODY> <FORM ACTION=scripts/resolver.pl method=post> <P>Enter an IP address or Machine name:<BR> <INPUT NAME=xinput VALUE=""></P> <P><INPUT TYPE=SUBMIT value="Resolve"> </FORM> </BODY> </HTML>

Replies are listed 'Best First'.
RE: Not so cool name resolution
by myocom (Deacon) on Sep 15, 2000 at 00:12 UTC

    Speaking of name resolution, here's a handy little one-liner:

    perl -MSocket -e"print scalar gethostbyaddr(inet_aton(shift),1)"

    Note: This is Win32-style -e quoting--change it if you need to for your particular system. For that matter, this is untested on any other system, though I suspect it works fine.

RE: Not so cool name resolution
by Fastolfe (Vicar) on Sep 14, 2000 at 23:45 UTC
    You should not assume that every hostname starting with a number is an IP address. If you're going to do a regexp, why not go all the way: /^\d+(\.\d+){3}$/

    It's also common practice to examine the last part of the domain, since this must be alphabetic for hostnames: /\.\d+$/ Don't just do /\d$/, because "www3" is a valid hostname, though "www.3" is not.