EvilZone

Programming and Scripting => Web Oriented Coding => : uNk March 27, 2011, 01:22:54 AM

: [PERL] Example of connecting to IRC & Sending commands
: uNk March 27, 2011, 01:22:54 AM
Here's an example of what ever the title says:

:
#!/usr/bin/perl
#Example of connecting to IRC.
 
use IO::Socket::INET ;
use LWP::UserAgent;
use LWP::Simple;
use XML::Simple;
 
 

my $server = "irc.evilzone.org";
my $port = "6667";
my $nick ="uNksBot";
my $name = "unk bot 8 *";
my $channel = "#evilzone";
 
system('cls');
system('title uNkBot');
print "\n\n\n\n Welcome.\n" ;
print "Activating... [Please wait]\n" ;
 
print " \n\n                                                    Version 1.0 \n\n";
print "\n [+] Now connecting to $server [Please wait]...\n";
 

$connection = IO::Socket::INET->new(PeerAddr=>"$server",
                                                PeerPort=>"$port",
                                                Proto=>'tcp',
                                                Timeout=>'30') or print " [!] Error $server\n";
print " [-] Now connected to $server [uNkBot]\n\n";
 
                                                       
print $connection "USER $name\n";
print $connection "NICK $nick\r\n";
 

while($response = <$connection>)
{
     
   print $response;
   
   
     if($response =~ m/:(.*) 00(.*) (.*) :/)
     {
          print $connection "JOIN $channel\r\n";
         }
 
   
        if($response =~ m/:!hey/)
                {
                print $connection "PRIVMSG $channel :Ohai\r\n";
                }
 
 
 
               
         if( $response =~ m/:(.*)!~(.*) JOIN :/)
         {
             my $rc = $1 ;
                 print $connection "PRIVMSG $channel :$rc <Welcome.\r\n";   
         }
 
               
        if( $response =~ m/:(.*)!~(.*) QUIT :/)
        {
         my $rc = $1 ;
                print $connection "PRIVMSG $channel :Bye.\r\n";     
        }
 
 
           
        if($response =~ m/^PING (.*?)$/gi)
        {
         print $connection "PONG ".$1."\r\n";
        }
}

If you want to add more commands without !hey, just add one more of these lines just edit it like this:

:
        if($response =~ m/:!bitch/)
                {
                print $connection "PRIVMSG $channel :No you.\r\n";
                }
: Re: [PERL] Example of connecting to IRC & Sending commands
: ande March 27, 2011, 01:46:15 AM
Sweet, I will for real have use of this for a Snort module ;)