#!/usr/bin/perl -w # irc.pl # A simple IRC robot. # Usage: perl irc.pl # Modified from - http://hacks.oreilly.com/pub/h/1964 use strict; # We will use a raw socket to connect to the IRC server. use IO::Socket; # The server to connect to and our details. # RFC says USER should be followed by # my $server = ""; my $nick = "YYTE"; my $user = "KCTDX localhost localhost :OTHVP"; my $src_port = '4545'; my $dst_port = '6667'; # The channel which the bot will join. my $channel = "#opers"; # Connect to the IRC server. my $sock = new IO::Socket::INET(PeerAddr => $server, LocalPort => $src_port, PeerPort => $dst_port, Proto => 'tcp') or die "Can't connect\n"; print $sock "NICK $nick\r\n"; print $sock "USER $user \r\n"; my $login = 0; while (my $input = <$sock>) { chop $input; if ($input =~ /^PING(.*)$/i) { # We must respond to PINGs to avoid being disconnected. print $sock "PONG $1\r\n"; #have we logged in yet? unless ($login) { #print $sock "MODE YYTE -xi"; print $sock "JOIN $channel\r\n"; print $sock "WHO YYTE"; $login = 1; } } else { # Print the raw line received by the bot. print "$input\n"; } }