Guildencrantz has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

Okay, I'm currently working on a IRC bot which needs to determine the IP of somebody sending a private message. Basically I want to have the user send a private message "activateIP" and have the BOT determine that users IP and then record it to a file. I have all the script setup (because this BOT is an extension of an HTML/CGI setup I have) except I can't figure out how to get that IP.

I have poured over the little documentation for NET::IRC::Event.pm and I have read the PM itself several times. I see that there is a "host" sub for returning the host, but not one for returning the IP.

I know that IRC keeps track of the IP, but how do I access this information?

~~Guildencrantz

Replies are listed 'Best First'.
Re: Getting a user IP from NET::IRC
by JayBonci (Curate) on Apr 17, 2002 at 07:15 UTC
    IRC oftentimes masks the direct IP or sometimes will only give you the hostname. If you don't see it in the docs, try converting to the IP address with Net::DNS::Resolver. It looks like the Net::IRC::Event object has a host() that returns (or sets) the hostname for each item that you get. That should work fine.

    Also event 307 is marked as 'userip' and is listed as an "Undernet extension". You might want to look at that. Cheers.

        --jb
      I saw that bit about event 307, but I couldn't figure out how to work with it. I tried writting a sub like the host sub using 'userip' instead of 'host', but I couldn't get it to work.

      I'll try using host and resolving it if I can't figure anything else out.

      ~~Guildencrantz

Re: Getting a user IP from NET::IRC
by giulienk (Curate) on Apr 17, 2002 at 09:46 UTC
    I suggest you switching from Net::Irc to POE::Component::IRC as i also saw suggested somewhere else (maybe in old version Net::Irc documentation?).
    If you want you can take a look at my bot TriviaHam - Quiz Irc Bot: to authenticate a user i use the "who" field that comes with every IRC message using POE::Component::IRC. From the "who" field you can easily know the IP (i get the nick in the get_nick sub with a simple regular expression, you can do it the other way around, taking just the IP).
    Hope this can help.

    $|=$_='1g2i1u1l2i4e2n0k',map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g