• Publicidad

Ayuda con HTTP::Proxy

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Ayuda con HTTP::Proxy

Notapor BigBear » 2014-01-01 17:03 @752

Hola, tengo el siguiente código:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. #A simple Proxy Server
  3. #(C) Doddy Hackman 2011
  4. #ppm install http://theoryx5.uwinnipeg.ca/ppms/HTTP-Proxy.ppd
  5.  
  6. use HTTP::Proxy;
  7. use HTTP::Proxy::BodyFilter::simple;
  8. use HTTP::Proxy::BodyFilter::complete;
  9.  
  10. my $port = "8083";
  11. my $logs = "logs.txt";
  12.  
  13. print "\n\n[+] Proxy server Online in port $port\n\n";
  14.  
  15. my $server = HTTP::Proxy->new(port=>$port);
  16. $server->host();
  17.  
  18. $server->push_filter(mime=>undef,response => HTTP::Proxy::BodyFilter::complete->new());
  19.  
  20. $server->push_filter(
  21. mime=>undef,
  22. request=>HTTP::Proxy::BodyFilter::simple->new(\&enable),
  23. response => HTTP::Proxy::BodyFilter::simple->new(\&enable2));
  24.  
  25. $server->start();
  26.  
  27. sub enable {
  28.  
  29. my @logs;
  30. my($a,$b,$c,$d,$e) = @_;
  31. my ($f,$g)=($c->header("cookie"),$c->header("x-requested-with"));
  32. my ($h,$i)=($c->header("content-type"),$c->header("content"));
  33.  
  34. savefile($logs,"\n[Peticion] : ".$c->method." ".$c->uri);
  35. savefile($logs,"[Cookie] : ".$f) if $f;
  36. savefile($logs,"[x-requested-with] : ".$g) if $g;
  37. savefile($logs,"[Content Type] : ".$h) if $h;
  38. savefile($logs,"[Content] : ".$i) if $i;
  39. savefile($logs,"");
  40.  
  41. }
  42.  
  43. sub enable2 {
  44. my ($j,$k,$l,$m,$n) = @_;
  45. savefile($logs,"\n\n[START]\n\n".$$k."\n\n[END]\n") if $$k ne "";
  46. }
  47.  
  48. sub savefile {
  49. open (SAVE,">>".$_[0]);
  50. print SAVE $_[1]."\n";
  51. close SAVE;
  52. }
  53.  
  54. # ¿ The End ?
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4


El tema es cuando lo quiero usar por segunda vez, o sea, cierro el primero y lo cargo de nuevo me da este error:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
[+] Proxy server Online in port 8083

Cannot initialize proxy daemon: La dirección ya se está usando at /usr/local/share/perl/5.10.1/HTTP/Proxy.pm line 271.
 
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


¿ Qué hago para corregir esto ?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: Ayuda con HTTP::Proxy

Notapor explorer » 2014-01-01 17:27 @768

El mensaje de error dice que el puerto está ocupado por otra aplicación.

Con el siguiente comando puedes saber qué programa lo está ocupando:

lsof -i :8083
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Ayuda con HTTP::Proxy

Notapor BigBear » 2014-01-01 17:40 @777

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
perl    2460 doddy    3u  IPv4  30946      0t0  TCP localhost:1111 (LISTEN)
perl    2461 doddy    3u  IPv4  30946      0t0  TCP localhost:1111 (LISTEN)
perl    2461 doddy    4u  IPv4  30975      0t0  TCP localhost:1111->localhost:38957 (CLOSE_WAIT)
 
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


¿ Qué hago ?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Ayuda con HTTP::Proxy

Notapor explorer » 2014-01-01 20:50 @909

Son procesos que tú has arrancado, así que puedes matarlos con el comando kill.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Ayuda con HTTP::Proxy

Notapor BigBear » 2014-01-02 10:50 @493

Gracias por la ayuda, explorer. El código quedó así:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use HTTP::Proxy;
  2. use HTTP::Proxy::BodyFilter::simple;
  3. use HTTP::Proxy::BodyFilter::complete;
  4. use Data::Dumper;
  5.  
  6. my $server = HTTP::Proxy->new( port => 8080 );
  7. $server->host();
  8.  
  9. $server->push_filter( mime => undef, response => HTTP::Proxy::BodyFilter::complete->new() );
  10.  
  11. $server->push_filter(
  12.     mime     => undef,
  13.     request  => HTTP::Proxy::BodyFilter::simple->new( \&enable ),
  14.     response => HTTP::Proxy::BodyFilter::simple->new( \&enable2 )
  15. );
  16.  
  17. $server->start();
  18.  
  19. sub enable {
  20.  
  21.     my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
  22.  
  23.     #print $$dataref;
  24.     #print Dumper $message;
  25.     print "url : " . $message->uri;
  26.  
  27.     #print Dumper $buffer;
  28.  
  29. }
  30.  
  31. sub enable2 {
  32.     my ( $j, $k, $l, $m, $n ) = @_;
  33.     savefile( $logs, "\n\n[START]\n\n" . $$k . "\n\n[END]\n" ) if $$k ne "";
  34. }
  35.  
  36. sub savefile {
  37.     open( SAVE, ">>" . $_[0] );
  38.     print SAVE $_[1] . "\n";
  39.     close SAVE;
  40. }
  41.  
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4


En el primer enable trato de mostrar el URI pero lo raro es que si no uso "print $$k" en el segundo enable el URI no se muestra. Lo he probado varias veces así y siempre raro, me parece raro que si no uso "print $$k" en el segundo el primero no me muestre el URI.

¿ Me podrías ayudar ?
Última edición por explorer el 2014-01-02 17:57 @789, editado 1 vez en total
Razón: Formateado de código con Perltidy
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Re: Ayuda con HTTP::Proxy

Notapor explorer » 2014-01-02 18:02 @793

Será porque $k es una referencia... entonces $$k es el valor referenciado...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Ayuda con HTTP::Proxy

Notapor BigBear » 2014-01-02 18:13 @801

Perdón, no entiendo qué tengo que hacer, ¿cómo arreglo esas líneas para que ande?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 6 invitados

cron