Connect to an IRC Server

Perl

Public Domain

Connects to an IRC server, identifies, joins a channel, responds to ping requests.

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl

#i've got more to add....will be done later

use IO::Socket;

$server = ''; # irc.server.com
$port = '';   # 6667
$nick = '';   # nick!user@host.com
$user = '';   # nick!user@host.com
$real = '';   # nick!user@host.com:Real Name
$channel = "";# #channel

my $sock = new IO::Socket(PeerAddr => $server,
                          PeerPort => $port,
                          Proto => 'tcp') or die "Connection Error [$1]";

print $sock "NICK $nick\r\n";
print $sock "USER $user server server :$real\r\n";

$x=0;
while($resp = <$sock>) {
#   print $resp;
    chop $resp;
    if($resp =~ /^PING(.*)$/i) {
        print $sock "PONG $1\r\n";
    }
    if(($resp =~ /376/) && ($x = 0)){print $sock "JOIN $channel\r\n";$x++;}}
}