elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Funcion Ip Publica [Perl]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Funcion Ip Publica [Perl]  (Leído 2,973 veces)
isseu


Desconectado Desconectado

Mensajes: 325


°º¤ø,¸¸,El conocimiento es poder°º¤ø,¸¸,ø¤º°`°º¤ø,


Ver Perfil WWW
Funcion Ip Publica [Perl]
« en: 19 Abril 2010, 03:55 am »

Una funcion que hice para probar un poco de "regex", usando la web http://ip.interchile.com/ devuelve tu ip publica como string,
Código
  1. #!/usr/bin/perl
  2. $ip=GetPublicIp();
  3. if($ip ne "Error"){
  4. print $ip;
  5. }else{
  6. print "Error";
  7. }
  8.  
  9. sub GetPublicIp{
  10. #Funcion Por Isseu
  11. use LWP::Simple;
  12. use LWP::UserAgent;
  13. use HTTP::Request;
  14. use HTTP::Response;
  15. $URL="http://ip.interchile.com/";
  16. $browser = LWP::UserAgent->new();
  17. $browser->timeout(5);
  18. my $request = HTTP::Request->new(GET => $URL);
  19. my $response = $browser->request($request);
  20. if(!$response->is_error()){
  21. $data=$response->content();
  22. $data=substr($data,630,50);
  23. if($data=~/<font size=7>(.+\..+\..+\..+)<\/font>/){
  24.    return $1;
  25.    }else{
  26. print "Error";
  27. }
  28.  
  29.  
  30. }else{
  31. print "Error";
  32. }
  33. }




En línea

~ Yoya ~
Wiki

Desconectado Desconectado

Mensajes: 1.125



Ver Perfil
Re: Funcion Ip Publica [Perl]
« Respuesta #1 en: 7 Mayo 2010, 23:58 pm »

estas usando modulos de mas, y podrias usar una expresion mas corta, asi no gasta mas recursos...


En línea

Mi madre me dijo que estoy destinado a ser pobre toda la vida.
Engineering is the art of balancing the benefits and drawbacks of any approach.
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
***
Desconectado Desconectado

Mensajes: 3.069


/^$/


Ver Perfil WWW
Re: Funcion Ip Publica [Perl]
« Respuesta #2 en: 8 Mayo 2010, 00:17 am »

Código
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use LWP::Simple;
  5. my $ip = get("http://icanhazip.com/");
  6. print $ip;
En línea

Código
  1. (( 1 / 0 )) &> /dev/null || {
  2. echo -e "stderrrrrrrrrrrrrrrrrrr";
  3. }
  4.  
http://leonardogtzr.wordpress.com/
leogutierrezramirez@gmail.com
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Perl] Funcion Speak()
Scripting
BigBear 0 1,539 Último mensaje 10 Octubre 2011, 16:51 pm
por BigBear
[Perl] Funcion wormer()
Scripting
BigBear 0 1,375 Último mensaje 10 Octubre 2011, 16:51 pm
por BigBear
[Perl] Funcion writeword()
Scripting
BigBear 0 1,423 Último mensaje 10 Octubre 2011, 16:52 pm
por BigBear
[Perl] Funcion movewin()
Scripting
BigBear 0 1,379 Último mensaje 11 Octubre 2011, 18:08 pm
por BigBear
[Perl] Funcion killprocess()
Scripting
BigBear 0 1,451 Último mensaje 11 Octubre 2011, 18:09 pm
por BigBear
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines