http://qs321.pair.com?node_id=1062687


in reply to How to deal with multiple functions served from only one input field?

You say "a single text field" but your examples refer to two different fields: address and ip, so I am unsure what you want to do.

If you have text fields address and ip, perhaps you could do something like:

use strict; use warnings; use CGI; use Net::Whois::Raw; use Net::Whois::ARIN; my $q = new CGI; my $domname = $q->param("domname"); my $ip = $q->param('ip'); print "content-type:text/plain; charset=utf-8\n\n"; if (!$domname) { print ""; } else { my $text = get_whois($domname, undef, "QRY_LAST"); print $text; } my $w = Net::Whois::ARIN->new( host => 'whois.arin.net', port => 43, timeout => 30, ); if (!$ip) { print ""; } else { my @records = $w->network($ip); foreach my $net (@records) { # print ...; } }

But, if you have a single text field (I have guessed the single field is named 'server'), maybe something like this:

use strict; use warnings; use CGI; use Net::Whois::Raw; use Net::Whois::ARIN; my $w = Net::Whois::ARIN->new( host => 'whois.arin.net', port => 43, timeout => 30, ); my $q = new CGI; my $server = $q->param("server"); print "content-type:text/plain; charset=utf-8\n\n"; if($server and $server ne "") { print "get_whois says:\n"; print get_whois($server, undef, "QRY_LAST"); print "\n\n"; print "ARIN says:\n"; my $output = $w->query("n + $server"); print "$output\n"; } else { print "No server\n"; }

You could check the server parameter to see if it looks like a domain name or a network address then call one function or the other accordingly, or call both functions and report both results, or check the results and only report "successful" results, for whatever you consider a successful lookup.