All pastes #356320 Raw Edit

Something

public text v1 · immutable
·published 2007-02-15 00:38 UTC
rendered paste body
use Irssi 20020300;
use strict;
use Socket;

use vars qw($VERSION %IRSSI);
$VERSION = "0.01";
%IRSSI = (
        authors         => "Vasya Pupkin",
        contact         => "vasya\@mother-russia.su",
        name            => "lwho",
        description     => "prints owner of ip/host in current channel",
        license         => "BSD",
        changed         => "yesterday"
);

Irssi::command_bind 'lwho' => sub {
        my ($arg, $server, $winit) = @_;
my $hostname;
my $ip;

if ($arg =~ /^[0-9\.]*$/) {
        # ip -> host
        $hostname = gethostbyaddr(inet_aton($arg), AF_INET);
        $ip = $arg;
        } else {
        # host -> ip
        my @addrs = gethostbyname($arg);
        if (@addrs) {
                @addrs = map { inet_ntoa($_) } @addrs[4 .. $#addrs];
                $ip = join (" ", @addrs);
                $hostname = $arg;
        }
}
for my $hash ($winit->nicks()) {
        if (defined $ip && $hash->{host} =~ /\@$ip$/) {
                Irssi::print("$hash->{nick} $hash->{host}");
                return;
                }
        if (defined $hostname && $hash->{host} =~ /\@$hostname$/) {
                Irssi::print("$hash->{nick} $hash->{host}");
                return;
                }
        }
                Irssi:print ("Looks like nobody from \'$arg\' is in \'$winit->{name}\'");
}