#host <ip>|<hostname>|<ip-in-hex>
use utf8;
use Socket;
sub host
{
    my ($msg) = @_;
    my ($ip, $hex, $host);

    if ($msg =~ /^\d{1,3}(\.\d{1,3}){3}$/)
    {
        $ip   = $msg;
        $hex  = unpack("H*", pack("C4", split /\./, $msg));
        $host = gethostbyaddr(inet_aton($msg), AF_INET);
        $msg = "$ip == $hex == $host";
    }
    elsif ($msg =~ /^([0-9a-z-]+\.)+([0-9a-z-]{2,4})$/)
    {
        $ip   = join(".", unpack("C4", ((gethostbyname($msg))[4])));
        $hex  = unpack("H*", pack("C4", split /\./, $ip));
        $host = $msg;
        $msg = "$ip == $hex == $host";
    }
    elsif ($msg =~ /^[a-f0-9]{8}$/i)
    {
        $ip   = join(".", unpack("C4", pack("H*", $msg)));
        $hex  = $msg;
        $host = gethostbyaddr(inet_aton($ip), AF_INET);
        $msg = "$ip == $hex == $host";
    }
    else
    {
        $msg = "Geen (geldige) argumenten opgegeven. Zie: help host";
    }
    return ($ip eq '' || $host eq '') ? 'Host/ip niet gevonden.' : $msg;
}

sub host_help
{
    return "Zet een hostname/IP om: host <ip>|<hostname>|<ip-in-hex>\nBv.: host google.com";
}

1;
