Advertisement
acesso

Untitled

Nov 24th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.32 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4.  
  5. use URI::Escape;
  6. use WWW::Curl;
  7. use WWW::Curl::Share;
  8. use WWW::Curl::Easy;
  9.  
  10. sub do_curl {
  11.         my ($url,$referer,$postfields);
  12.         ($url,$referer,$postfields) = @_;
  13.         my $header;
  14.         my $body;
  15.         my $curl = WWW::Curl::Easy->new;
  16.  
  17.         $curl->setopt(CURLOPT_HEADER,1);
  18.         $curl->setopt(CURLOPT_FOLLOWLOCATION,1);
  19.         $curl->setopt(CURLOPT_VERBOSE,0);
  20.         $curl->setopt(CURLOPT_URL, $url);
  21.         $curl->setopt(CURLOPT_REFERER, $referer);
  22.         $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36');
  23.  
  24.         $postfields = uri_escape($postfields);
  25.         $curl->setopt(CURLOPT_POSTFIELDS, $postfields);
  26.         $curl->setopt(CURLOPT_HEADERDATA, \$header);
  27.         $curl->setopt(CURLOPT_WRITEDATA,\$body);
  28.         my $retcode = $curl->perform;
  29.  
  30.         if ($retcode == 0) {
  31.                 print "Sucesso!\n";
  32.                 return $body;
  33.         } else {
  34.                 print("Falha\n");
  35.                 print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf.";\n");
  36.                 return 0;
  37.         }
  38. }
  39.  
  40. print do_curl('https://www.google.com.br/','https://www.google.com.br/','login=user&senha=senha');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement