Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IRC Bot.. problem

Status
Not open for further replies.

promyk

MIS
Dec 27, 2007
3
PL
Hi..

it's me again ;D

#!/usr/bin/perl
# Simple IRC Bot.
# Coded by: Saime.
# Options: !version , !killmaself , !op , !owner
# Visit us: irc.nitrousirc.net #perl
use strict;
use IO::Socket;
use Socket;
use Switch;
use LWP::UserAgent;
my $server = "irc.efnet.nl";
my $port= '6665';
my $chanel = "#mycanal";
my $nick = "BuasdadG";
my $identify = "BuasdadG2";
my $name = "BuasdadG124";
my $saime = "BuasdadG23";
my $socket = new IO::Socket::INET(PeerAddr => $server, PeerPort => $port, Proto => "tcp") or die "Get a life ?";
print $socket "NICK $nick\r\n";
print $socket "USER $identify 8 * :$name\r\n";
print $socket "JOIN $chanel\r\n";
while (my $body = <$socket>) {
chop $body;
if ($body =~ /^.*!md5(.*)/i) {
#HERE CONNCT
my $ua = new LWP::UserAgent;
$ua->agent("Mozilla/8.0");
$ua = LWP::UserAgent->new;
my $hash = $1;
$hash = $1;
my $req = HTTP::Request->new(POST => "$req->content_type('application/x-$req->content("hash=$hash&server=top&token=md5s&tryb=search&submit=submit");
my $res = $ua->request($req);
my $con = $res->content;
##############################################
if($con =~/(.*)<.font><.td><.tr><tr><td><font size="-1">/){
print $socket ("PRIVMSG $chanel not!\r\n");
}
elsif($con =~ /<font size="-1" color="green">{1}(.*)<.font>/){
my $pass = "$1";
print $socket ("PRIVMSG $chanel $pass!\r\n");
}
###################################################
}
}

This is IRC BOT..i try send with he's help POST to some site.. and when i send np

$req->content("hash=$hash&server=top&token=md5s&tryb=search&submit=submit");


it not work...
but when i $hash change to my MD5 is good.. why i can't use $hash.. ? i try

if ($body =~ /^.*!md5(.*)/i) {
#HERE CONNCT
my $ua = new LWP::UserAgent;
$ua->agent("Mozilla/8.0");
$ua = LWP::UserAgent->new;
my $hash = $1;
$hash = $1;

and dont work..

ps Help me ;)

SORRY FOR MY ENGLISH :(
 
try removing the second line and see if that helps:

my $hash = $1;
$hash = $1; <-- remove this one

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Always save your captured expressions IMMEDIATELY after the regular expression that created them. For one, this makes your code more self documenting. However, an even better reason is that any regex used in the constructor to LWP::UserAgent will overwrite those captured values.

Here is how I would reformat your code. I don't know exactly what your problem is, but .... shrug.

Code:
[gray]#!/usr/bin/perl[/gray]
[gray][i]# Simple IRC Bot.[/i][/gray]
[gray][i]# Coded by: Saime.[/i][/gray]
[gray][i]# Options: !version , !killmaself , !op , !owner[/i][/gray]
[gray][i]# Visit us: irc.nitrousirc.net #perl[/i][/gray]

[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]IO::Socket[/green][red];[/red]
[black][b]use[/b][/black] [green]Socket[/green][red];[/red]
[black][b]use[/b][/black] [green]Switch[/green][red];[/red]
[black][b]use[/b][/black] [green]LWP::UserAgent[/green][red];[/red]

[black][b]use[/b][/black] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$server[/blue]   = [red]"[/red][purple]irc.efnet.nl[/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$port[/blue]     = [red]'[/red][purple]6665[/purple][red]'[/red][red];[/red]
[black][b]my[/b][/black] [blue]$chanel[/blue]   = [red]"[/red][purple]#mycanal[/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$nick[/blue]     = [red]"[/red][purple]BuasdadG[/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$identify[/blue] = [red]"[/red][purple]BuasdadG2[/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$name[/blue]     = [red]"[/red][purple]BuasdadG124[/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$saime[/blue]    = [red]"[/red][purple]BuasdadG23[/purple][red]"[/red][red];[/red]

[black][b]my[/b][/black] [blue]$socket[/blue] = new [maroon]IO::Socket::INET[/maroon][red]([/red]
	[purple]PeerAddr[/purple] => [blue]$server[/blue],
	[purple]PeerPort[/purple] => [blue]$port[/blue],
	[purple]Proto[/purple]    => [red]"[/red][purple]tcp[/purple][red]"[/red],
[red])[/red] or [url=http://perldoc.perl.org/functions/die.html][black][b]die[/b][/black][/url] [red]"[/red][purple]Can't bind : [blue]$@[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [blue]$socket[/blue] [red]"[/red][purple]NICK [blue]$nick[/blue][purple][b]\r[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[black][b]print[/b][/black] [blue]$socket[/blue] [red]"[/red][purple]USER [blue]$identify[/blue] 8 * :[blue]$name[/blue][purple][b]\r[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[black][b]print[/b][/black] [blue]$socket[/blue] [red]"[/red][purple]JOIN [blue]$chanel[/blue][purple][b]\r[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]

[olive][b]while[/b][/olive] [red]([/red] [black][b]my[/b][/black] [blue]$body[/blue] = <[blue]$socket[/blue]> [red])[/red] [red]{[/red]
	[url=http://perldoc.perl.org/functions/chop.html][black][b]chop[/b][/black][/url] [blue]$body[/blue][red];[/red]
	
	[olive][b]if[/b][/olive] [red]([/red] [blue]$body[/blue] =~ [red]/[/red][purple]^.*!md5(.*)[/purple][red]/[/red][red]i[/red] [red])[/red] [red]{[/red]
		[black][b]my[/b][/black] [blue]$hash[/blue] = [blue]$1[/blue][red];[/red]

		[gray][i]# HERE CONNCT[/i][/gray]
		[black][b]my[/b][/black] [blue]$ua[/blue] = new LWP::UserAgent[red];[/red]
		[blue]$ua[/blue]->[maroon]agent[/maroon][red]([/red][red]"[/red][purple]Mozilla/8.0[/purple][red]"[/red][red])[/red][red];[/red]
		[blue]$ua[/blue] = LWP::UserAgent->[maroon]new[/maroon][red];[/red]
		[black][b]my[/b][/black] [blue]$req[/blue] = HTTP::Request->[maroon]new[/maroon][red]([/red]
			[purple]POST[/purple] => [red]"[/red][purple][URL unfurl="true"]http://md5search.org/index.php[/URL][/purple][red]"[/red],
		[red])[/red][red];[/red]
		[blue]$req[/blue]->[maroon]content_type[/maroon][red]([/red][red]'[/red][purple]application/x-www-form-urlencoded[/purple][red]'[/red][red])[/red][red];[/red]
		[blue]$req[/blue]->[maroon]content[/maroon][red]([/red][red]"[/red][purple]hash=[blue]$hash[/blue]&server=top&token=md5s&tryb=search&submit=submit[/purple][red]"[/red][red])[/red][red];[/red]
		[black][b]my[/b][/black] [blue]$res[/blue] = [blue]$ua[/blue]->[maroon]request[/maroon][red]([/red][blue]$req[/blue][red])[/red][red];[/red]
		[black][b]my[/b][/black] [blue]$con[/blue] = [blue]$res[/blue]->[maroon]content[/maroon][red];[/red]
		
		[olive][b]if[/b][/olive] [red]([/red] [blue]$con[/blue] =~ [red]/[/red][purple](.*)<.font><.td><.tr><tr><td><font size="-1">[/purple][red]/[/red] [red])[/red] [red]{[/red]
			[black][b]print[/b][/black] [blue]$socket[/blue] [red]([/red][red]"[/red][purple]PRIVMSG [blue]$chanel[/blue] not![purple][b]\r[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red])[/red][red];[/red]
		[red]}[/red]
		[olive][b]elsif[/b][/olive] [red]([/red] [blue]$con[/blue] =~ [red]/[/red][purple]<font size="-1" color="green">{1}(.*)<.font>[/purple][red]/[/red] [red])[/red] [red]{[/red]
			[black][b]my[/b][/black] [blue]$pass[/blue] = [red]"[/red][purple][blue]$1[/blue][/purple][red]"[/red][red];[/red]
			[black][b]print[/b][/black] [blue]$socket[/blue] [red]([/red][red]"[/red][purple]PRIVMSG [blue]$chanel[/blue] [blue]$pass[/blue]![purple][b]\r[/b][/purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red])[/red][red];[/red]
		[red]}[/red]
	[red]}[/red]
[red]}[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
Core (perl 5.8.8) Modules used :
[ul]
[li]IO::Socket - Object interface to socket communications[/li]
[li]Socket - load the C socket.h defines and structure manipulators[/li]
[li]Switch - A switch statement for Perl[/li]
[/ul]
Other Modules used :
[ul]
[li]LWP::UserAgent[/li]
[/ul]
[/tt]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top