#!/usr/bin/perl

#
# Author:   Erik Heinz <erik@iks-jena.de>
# Copyright:  GPL
# Version:  2004-03-09
#


use Getopt::Std;
use Encode;
require whois;


getopts('a:h:rv');

($search) = @ARGV;

if (!$search) { die "whois [-h hostname] [-a age] [-r] name\n"; }

if ($opt_r) { $opt_a = 1; }
elsif (!$opt_a) { $opt_a = 86400; }

($result, $host) = whois::whois($search, $opt_h, $opt_a, $opt_v);

if ($result =~ /[\240-\377]/) {
  if (whois::check_utf8($result)) {
    if ($ENV{'LANG'} !~ /UTF-8/) { $result = decode('utf-8', $result); } }
  else {
    if ($ENV{'LANG'} =~ /UTF-8/) { $result = encode('utf-8', $result); } }
}

print "$result\n";

