Chinaunix首页 | 论坛 | 博客
  • 博客访问: 593113
  • 博文数量: 158
  • 博客积分: 2696
  • 博客等级: 少校
  • 技术积分: 1668
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-10 00:49
个人简介

life?is?short?,?play?more!

文章分类

全部博文(158)

文章存档

2021年(1)

2013年(10)

2012年(4)

2011年(11)

2010年(27)

2009年(28)

2008年(52)

2007年(25)

我的朋友

分类: LINUX

2010-04-14 16:08:00


#!/usr/bin/perl -w

use Digest::MD5 qw(md5 md5_hex md5_base64);
use Encode;

use Socket;

################

#intialize the sock

sub open_TCP
{
  # get parameters

  my ($FS, $dest, $port) = @_;
 
  my $proto = getprotobyname('tcp');
  socket($FS, PF_INET, SOCK_STREAM, $proto);
  my $sin = sockaddr_in($port,inet_aton($dest));
  connect($FS,$sin) || return undef;
  
  my $old_fh = select($FS);
  $| = 1;          # don't buffer output

  select($old_fh);
  return 1;
}



sub get_url
{
my @headers,@contents;
@headers=();  //清空数据
@contents=();  //清空数据
my ($url) = @_;
if ($url =~ /^http:\/\/(.+?):([0-9]+)\//) {

    $web_server = $1;
    $port = $2;
}

elsif ($url =~ /^http:\/\/(.+?)\// ) {
  $web_server = $1;
  $port = 80;
}

else {
print "plz give the correct url\n";
exit(-1);
}

#print $web_server.":".$port."\n\n";


if (open_TCP(F, $web_server, $port) == undef) {
  print "Error connecting to server at $!\n";
  exit(-2);
}

print F "GET ".$url." HTTP/1.1\r\n";
print F "HOST: $web_server\r\n";
print F "Connection: Close\r\n\r\n";


my @return_line=<F>;

#print @return_line;


close(F);
#my @headers,@contents;

my $lines = 0;
my $found_gap=0;

        while ($lines <= @return_line) {

        #print $lines;


                if ($found_gap == 0) {

                push (@headers,@return_line[$lines]);
                }

                if($found_gap ==1){

                push (@contents,@return_line[$lines]);
                }

                if (@return_line[$lines] =~ /^\r$/ && !$found_gap) {

                #print "found the gap bettween the headers and content.\n";

                $found_gap=1;

                }

        $lines ++;

        }


#print @headers;


#print "##########\n";


#print @contents;

return @contents;
}

####################post data#######################

#########return the body############################

####################################################

sub post_url

{

my ($url,$post_data,$urlencode_need) = @_;

if ($url =~ /^http:\/\/(.+?):([0-9]+)\//) {

    $web_server = $1;
    $port = $2;
    
}

elsif ($url =~ /^http:\/\/(.+?)\// ) {

  $web_server = $1;
  $port = 80;

}

else {

print "plz give the correct url\n";

exit(-1);

}


$length = length($post_data);

if ($urlencode_need) {

   #$post_data =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;

  $length = "57";
     #length($post_data);


   print "urlencoded data: $post_data\n";

}

#print $web_server.":".$port."\n\n";


if (open_TCP(F, $web_server, $port) == undef) {
  print "Error connecting to server at $!\n";
  exit(-2);
}

print F "POST ".$url." HTTP/1.1\r\n";
#print F "Accept: */*\r\n";

#print "Accept: */*\r\n";

#print F "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.18) Gecko/2010020220 Firefox/3.0.18\r\n";

print F "Content-Type: application/x-www-form-urlencoded\r\n";
print F "Content-Length: ".$length."\r\n";
#print "Content-Length: ".$length."\r\n";

print F "Host: $web_server\r\n";
#print F "Keep-Alive: 100\r\n";

#print F "Pragma: no-cache\r\n";

print F "Connection: Close\r\n\r\n";
#print "POST data: $post_data\r\n";

print F "$post_data\r\n";


my @return_line=<F>;
my @contents;
my @headers;
#print @return_line;


close(F);

my $lines = 0;
my $found_gap=0;

        while ($lines <= @return_line) {

        #print $lines;


                if ($found_gap == 0) {

                push (@headers,@return_line[$lines]);
                }

                if($found_gap ==1){

                push (@contents,@return_line[$lines]);
                }

                if (@return_line[$lines] =~ /^\r$/ && !$found_gap) {

                #print "found the gap bettween the headers and content.\n";

                $found_gap=1;
                }
        $lines ++;

        }

print "\n###############################################################\n";
print "Post Url: $url\n";
print "Post Data: $post_data\n";
print "#######################return headers##########################\n";
print @headers;
#print "#####body#####\n";

#print @contents;

return @contents;
}


sub random_password{
my $maxLenth=57;
my @a = (0..9);
my $password = join '', map { $a[int rand @a] } 0..($maxLenth-1);
return $password;
}

##################################get red-blue ###########################


print "begain to get the red-blue result\n";

my $i=1;

my $red_num = 0;

for(;$i<34;$i++) {

print "###########$i times##########\n";

@returns = ();
@returns = get_url("");

#print "";


my $number = @returns;

my $line = 0;

for(;$line<$number;$line++){

if ( @returns[$line] =~ /<td height=\"18\" align=\"center\" bgcolor=\"#FFFFFF\">([0-9]+)<\/td>/)
{
print "
red: $1";
system("
echo -n $1 >> ret");
$red_num=0;

}
if ( @returns[$line] =~ /

([0-9]+)<\/td>/)
{
print " red: $1";
system("
echo -n ',$1' >>ret");

$red_num ++;

if ($red_num eq 5 )
{
print "
\n";
system("
echo -n '\n' >> ret


阅读(877) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~