Government Security
Network Security Resources

Jump to content

Photo

Irc Bot In Perl

- - - - - server perl hash
  • Please log in to reply
52 replies to this topic

#1 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 27 October 2005 - 03:54 AM

#!/usr/bin/perl
#perl ircbot by netcomm

$server = "irc.efnet.net"; #server
$port = 6667; #port
$nick = "perlieBOT"; #nick
$ident = "perlieBOT"; #ident
$realname = "perlieBOT"; #realname
$chan = "#shiteaters"; #channel
$pass = ""; #pass
$su = ""; #super user


&connect;
sub connect {
use IO::Socket;

$irc=IO::Socket::INET->new(
PeerAddr=>$server,
PeerPort=>$port,
Proto=>'tcp')or die "Dead.. Dead.. DEAD!;


print "$nick has connected to $server on $chan\n";
print $irc "USER $ident $ident $ident $ident :$realname\n";
print $irc "NICK $nick\n";
print $irc "PRIVMSG nickserv/@/services.dal.net :identify $pass\n";
print $irc "join $chan\n";
print $irc "PRIVMSG $owners :$nick is online\n";

while(defined($in=<$irc>)){




### Start of commands



if($in=~/^:(.+)\!.+ JOIN\b/){print $irc "PRIVMSG $1 :hello $1 welcome to $chan\n";}
if($in=~/PING(.*)/){print $irc "PONG :$1\n";} # MUST LEAVE THIS LINE
print "$in\n"; # AND THIS ONE



next unless $in =~ /^:$owners\b/; #makes bot only respond to owner


sub about {
if($in=~/!about/)
{print $irc "PRIVMSG $chan :I am a ircbot written in perl by netcomm\n";}
}

sub opdeop {
if($in=~/!op /)
{print $irc "MODE $chan +o $'\n";}
if($in=~/!deop /)
{print $irc "MODE $chan -o $'\n";}
}

sub joinpart {
if($in=~/!join / & $in=~/$su/)
{print $irc "join :$'\n";}
if($in=~/!part / & $in=~/$su/)
{print $irc "part :$'\n";}
}

sub kickban {
if($in=~/!kickban /)
{print $irc "kick $chan $' :TXTbot ownz da world\n";}
if($in=~/!kickban /)
{print $irc "mode $chan +b $'\n";}
}

sub kick {
if($in=~/!kick /)
{print $irc "kick $chan $' :TXTbot ownz da world\n";}
}

sub raw {
if($in=~/!raw / & $in=~/$su/)
{print $irc " $'\n";}
}

sub say {
if($in=~/!say /)
{print $irc "PRIVMSG $chan :$'\n";}
}

sub quit {
if($in=~/!quit/ & $in=~/$su/)
{print $irc "PRIVMSG $chan :Seya\n";}
if($in=~/!quit/)
{print $irc "QUIT\n";}
}

sub name {
if($in=~/!nick / & $in=~/$su/)
{print $irc "nick :$'\n";}
}

sub rehash {
if($in=~/!rehash/ & $in=~/$su/)
{print $irc "PRIVMSG $chan :Rehashing...\n";}
if($in=~/!rehash/ & $in=~/$su/)
{print $irc "QUIT\n";}
if($in=~/!rehash/ & $in=~/$su/){
system("bot.pl");}
if($in=~/!rehash/ & $in=~/$su/){
print $irc "join $chan";}
}

sub viewusers {
if($in=~/!users/)
{print $irc "PRIVMSG $chan :Current Users:$owners\n";}
}

sub res2 {
if($in=~/!res2/){
open(OUTPUT_FILE, ">>bot.pl");}
if($in=~/!res2/){
print OUTPUT_FILE "\n" x $line, " " x $row, $char, "\n";}
if($in=~/!res2/){close(OUTPUT_FILE);}
if($in=~/!res2/){print $irc "PRIVMSG $chan :DONE!\n";}
}


#sub calls
&res2;
&viewusers;
&rehash;
&raw;
&kickban;
&say;
&name;
&kick;
&about;
&opdeop;
&joinpart;
&quit;

}
close($irc);


I know its pritty sloppy code but it works.......

#2 toe

toe

    Staff Sergeant

  • Members
  • 271 posts

Posted 27 October 2005 - 04:34 AM

This does not work with activeperl on windows to many errors to paste. Maybe you could upload the text/pl file or post it in with the code tags so it doesnt get as messed up. I noticed the sad.gif so i replaced that with : ( and still get many errors. Could you also list all the commands aswell because i might missed some of them.

-toe

#3 Nick W

Nick W

    First Sergeant

  • Members
  • 1,250 posts

Posted 27 October 2005 - 05:24 AM

netcomm, I actually have an interest in this for an AI project I've been toying with over the last few years. Could you please repost with "CODE" tags around it?

#4 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 27 October 2005 - 11:19 PM

#!/usr/bin/perl
#perl ircbot by netcomm 


#lets set some varibles

$server = "irc.efnet.net";	 #server 
$port = 6667;					#port
$nick = "perlieBOT";			 #nick
$ident = "perlieBOT";			#ident
$realname = "perlieBOT";		 #realname
$chan = "#shiteaters";			   #channel
$pass = "";				#pass
$su = "NetComm";				 #super user
$owners = "NetComm";	  #owners




use IO::Socket;

$irc=IO::Socket::INET->new(
		PeerAddr=>$server,
		PeerPort=>$port,
		Proto=>'tcp')or die "DEAD!";
		
				print "PerlBot by netcomm\n";
				print "$nick has connected to $server on $chan\n";
				print $irc "USER $ident $ident $ident $ident :$realname\n";
				print $irc "NICK $nick\n";
				print $irc "PRIVMSG nickserv/@/services.dal.net :identify $pass\n";
				print $irc "join $chan\n";
				print $irc "PRIVMSG $owners :$nick is online\n";
			   
			   while(defined($in=<$irc>)){
					  
						
						
						 
							### Start of commands   
						



if($in=~/^:(.+)\!.+ JOIN\b/){print $irc "PRIVMSG $1 :hello $1 welcome to $chan\n";}
if($in=~/PING(.*)/){print $irc "PONG :$1\n";} # MUST LEAVE THIS LINE
print "$in\n"; # AND THIS ONE



next unless $in =~ /^:$owners\b/; #makes bot only respond to owner
 

sub about {
if($in=~/!about/)
{print $irc "PRIVMSG $chan :I am a ircbot written in perl by netcomm\n";}
}

sub opdeop {
if($in=~/!op /)
{print $irc "MODE $chan +o $'\n";}
if($in=~/!deop /)
{print $irc "MODE $chan -o $'\n";}
}

sub joinpart {
if($in=~/!join / & $in=~/$su/) 
{print $irc "join :$'\n";}
if($in=~/!part / & $in=~/$su/)
{print $irc "part :$'\n";}
}
				
sub kickban {
if($in=~/!kickban /)
{print $irc "kick $chan $' :TXTbot ownz da world\n";}
if($in=~/!kickban /)
{print $irc "mode $chan +b $'\n";}
}

sub kick {
if($in=~/!kick /)
{print $irc "kick $chan $' :TXTbot ownz da world\n";}
}

sub raw {
if($in=~/!raw / & $in=~/$su/)
{print $irc " $'\n";}
}


sub say {
if($in=~/!say /)
{print $irc "PRIVMSG $chan :$'\n";}
}
 
sub quit {
if($in=~/!quit/ & $in=~/$su/)
{print $irc "PRIVMSG $chan :Seya\n";}
if($in=~/!quit/)
{print $irc "QUIT\n";}
}

sub name {
if($in=~/!nick / & $in=~/$su/)
{print $irc "nick :$'\n";}
}

sub rehash {
if($in=~/!rehash/ & $in=~/$su/)
{print $irc "PRIVMSG $chan :Rehashing...\n";}
if($in=~/!rehash/ & $in=~/$su/)
{print $irc "QUIT\n";}
if($in=~/!rehash/ & $in=~/$su/){
system("bot.pl");}
if($in=~/!rehash/ & $in=~/$su/){
print $irc "join $chan";}
}

sub viewusers {
if($in=~/!users/)
{print $irc "PRIVMSG $chan :Current Users:$owners\n";}
}


#sub calls

&viewusers;
&rehash;
&raw;
&kickban;
&say;
&name;
&kick;
&about;
&opdeop;
&joinpart;
&quit;

}
close($irc);

Sorry about that there ya go..

Commands are as follows:
NOTE:Discard the <>'s duh.

!op <nick>
!deop <nick>
!join <chan>
!part <chan>
!kickban <nick>
!kick <nick>
!raw <raw> - is a bit tech need to add a little regex there.
!say <whatever>
!quit
!name <nick> - changes nickname of bot till next restart/rehash
!rehash - reboots bot
!viewusers - just displays owner - i didn't get around to finishing userlists, mainly cause i wanted to keep it stand alone.
!about - says i made it.... :)

Peace.

#5 toe

toe

    Staff Sergeant

  • Members
  • 271 posts

Posted 28 October 2005 - 04:40 AM

Also how do i add multi su's and owners so more ppl can scrw around with it?

This doesnt work but could you reply with an example like this? Or isn't this supported yet?
$su = "toe, anus, guest";
$owners = "NetComm, anus, guest";

-toe

#6 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 28 October 2005 - 05:24 PM

well basicly i havent got that far,

bit if you want to allow public commands remove

next unless $in =~ /^:$owners\b/; #makes bot only respond to owner

and all the subs that dont have
$in=~/$su/ will be public..

ill have a play and get a userlist happening for you tho..
peace.

#7 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 31 October 2005 - 08:56 PM

Ive added a couple of commands if you interested:

A DNS getter:

Put these before: next unless $in =~ /^:$owners\b/; #makes bot only respond to owner
if($in=~/^:.+ 302 $nick :(.+[^*=+])\*?=\+?(.+[^*=+])@(.+)$/)
{
my $nickn = $1;
my $ident = $2;
my $dns = $3;
print $irc "PRIVMSG $chan :Ident:$ident Dns:$dns\n";
}

if($in=~/^:(.+)252 perlieBOT(.+)$/){
my $opers = $2;
sub opers {
if($in=~/!oper/){
print $irc "PRIVMSG $chan :$opers\n";
}}}

And this after:

sub dns {
if($in=~/!getinfo(.+)/ ) 
{print $irc "USERHOST :$1";}
}

And add &dns; to the sub calls at the bottom...

New Commands are,

!getinfo <nick> - will reply with Ident and DNS in channel.
!oper - Shall display current opers online on your server.

Stay tune and let me know if you want anything...

BTW: userlist is almost done..

Peace

#8 320X

320X

    Staff Sergeant

  • Members
  • 474 posts

Posted 01 November 2005 - 09:43 AM

great irc-bot code nfetcomm thanks to share it :)

#9 Skydriver

Skydriver

    Specialist

  • Members
  • 102 posts

Posted 01 November 2005 - 10:03 AM

is there any reason y i get this error ?


NOTICE AUTH :*** Looking up your hostname...

NOTICE AUTH :*** Checking Ident

NOTICE AUTH :*** Found your hostname

NOTICE AUTH :*** No Ident response

PING :82D9AF38

:irc.servercentral.net 451 * :You have not registered

#10 SkitZZ

SkitZZ

    Specialist

  • Members
  • 139 posts

Posted 01 November 2005 - 03:47 PM

just googled the error "451 * :You have not registered" first hit gave me this answer ;)

451 ERR_NOTREGISTERED
":You have not registered"

- Returned by the server to indicate that the client
MUST be registered before the server will allow it
to be parsed in detail.

SkitZZ

#11 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 01 November 2005 - 09:33 PM

No idear why that is happening,
The registration is covered in here..

print $irc "USER $ident $ident $ident $ident :$realname\n";

maybe you havent set a $ident varible or $realname..

should look somthing like;

$ident = "perlieBOT"; #ident
$realname = "perlieBOT"; #realname

btw i have added HEAPS of stuff to this bot over the last few day and shall continue to..
SO give me some suggestions and ill be posting new version soon.

Peace.

#12 Skydriver

Skydriver

    Specialist

  • Members
  • 102 posts

Posted 02 November 2005 - 01:43 AM

my mistake its working good

#13 toe

toe

    Staff Sergeant

  • Members
  • 271 posts

Posted 10 November 2005 - 05:44 AM

Remember function. eg "/remember gimp :im a gimp" So it would remember the word gimp and when someone chatting says gimp it will responed to it. I am able to code in responses in the source:

sub responses {
if($in=~/gimp/)
{print $irc "PRIVMSG $chan :Im a gimp\n";}
if($in=~/netcomm/)
{print $irc "PRIVMSG $chan :i know netcomm he made me\n";}
}


I was able to do that and it worked, but that was just common sense (I don't know any perl). I want to know if there is a way to, instead of coding for every response how would you make it remember stuff when you told it to. Like /remember netcomm :i know netcomm he made me. im real tired and i think i repeated alot of stuff hope u get the point.

-toe

#14 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 16 November 2005 - 04:28 PM

Remember function. eg "/remember gimp :im a gimp" So it would remember the word gimp and when someone chatting says gimp it will responed to it. I am able to code in responses in the source:

sub responses {
if($in=~/gimp/)
{print $irc "PRIVMSG $chan :Im a gimp\n";}
if($in=~/netcomm/)
{print $irc "PRIVMSG $chan :i know netcomm he made me\n";}
}


I was able to do that and it worked, but that was just common sense (I don't know any perl). I want to know if there is a way to, instead of coding for every response how would you make it remember stuff when you told it to. Like /remember netcomm :i know netcomm he made me. im real tired and i think i repeated alot of stuff hope u get the point.

-toe


The easiest way i would think of would be somthing like this:

if($in=~/!remember (.*)/){
open(DAT,">>remember.txt") || die("Cannot Open File");
print DAT "$1";
close(DAT);
{print $irc "PRIVMSG $chan :$1 is now remembered!\n";}
}

then you would need to make specerate subs to call the text from..
Let me think about this.. it a little harder than i thought but i will get back to you....
In the mean time ive made a few things ;


Banner Grabber

sub bannergrab {

if($in=~/:(.+)!bannergrab (.+) (.+)\r$/){

if($3=~/80/){print $irc "PRIVMSG $chan :Http request are not supported, sorry.\n";}
else{
print $irc "PRIVMSG $chan :Grabbing Banner from $2 on port $3\n";
$bp = $3;
$bs = $2;
$connection=IO::Socket::INET->new(
			PeerAddr=>"$2",
			PeerPort=>$3,
			TImeOut=>"20",
		Proto=>'tcp')or &cant;

			while(defined($banner=<$connection>)){
   
   print $irc "PRIVMSG $chan :$banner";
   if($banner=~/Looking up your hostname/){print $irc "PRIVMSG $chan :$bs on port $bp is running a ircd\n";	   

close($connection);}
   if($banner=~/ftp/){print $irc "PRIVMSG $chan :$bs on port $bp is running a ftp server.\n"; close($connection);}  
   if($banner=~/ssh/){print $irc "PRIVMSG $chan :$bs on port $bp is running a ssh server.\n"; close($connection);}
   if($banner=~/SSH/){print $irc "PRIVMSG $chan :$bs on port $bp is running a ssh server.\n"; close($connection);}
   close($connection);}}
sub cant {
print $irc "PRIVMSG $chan :can't connect to $2 on port $3\n";
}}}
POrt Scanner, Only scans one ip at a time...

if($in=~/pmap (.*) (.*) (.*)/){

$target = $1;
$port = $2;
$maxport = $3;


$daddr = inet_aton($target);

print $irc "PRIVMSG $chan :Scanning - $target ports $port to $maxport\r\n";
foreach (; $port<=$maxport; $port++) {
print $irc "PRIVMSG $chan :Port $port is open\r\n" if ( $socket = 

IO::Socket::INET->new(PeerAddr=>"$target:$port",Proto=>'tcp',Timeout=>1));
}
print $irc "PRIVMSG $chan :Pscan of $target has Finished\r\n";
close ($socket);
}}
Prints google news, requires www-google-news.pm

sub news {
if($in=~/!news/){
use WWW::Google::News (get_news);
  my $news = get_news();
  foreach my $topic (keys %{$news}) {
	for (@{$news->{$topic}}) {
	  print $irc "PRIVMSG $chan :Source: " . $_->{source} . "\n";
	  print $irc "PRIVMSG $chan :Topic: $topic\n";
	  print $irc "PRIVMSG $chan :Headline: " . $_->{headline} . "\n";
	  print $irc "PRIVMSG $chan :URL: " . $_->{url} . "\n";
	  print $irc "PRIVMSG $chan :Source: " . $_->{source} . "\n";
	  print $irc "PRIVMSG $chan :When: " . $_->{date} . "\n";
	  print $irc "PRIVMSG $chan :Summary: " . $_->{summary} . "\n";
	  print $irc "PRIVMSG $chan :__________________________________\n";
	  sleep(60);
		}
}
  }
}
sub time {
$time = localtime();
if($in=~/!time/)
{print $irc "PRIVMSG $chan :$time\n";}
}


REMEMBER to add the sub calls at the bottom..
and ill get back to you toe..

Peace
NetComm..

#15 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 17 November 2005 - 08:28 PM

Well i have perlieBOT a huge ass overhaul...

http://www.inithello.net/PerlieBOT.rar

Much sexier now...
can load plugins remotly....

Tell me what yall think.

Peace
NetComm.





Also tagged with one or more of these keywords: server, perl, hash