• Publicidad

Extraer solo una parte de una web

¿Ya sabes lo que es una referencia? Has progresado, el nível básico es cosa del pasado y ahora estás listo para el siguiente nivel.

Extraer solo una parte de una web

Notapor BigBear » 2009-06-09 17:32 @772

Hi!

Ando tratando de hacer un whois con un servicio web pero ya solo me falta que extraiga lo que yo quiero.

El code quedó así:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
use LWP::UserAgent;
use HTTP::Request::Common;


$url = "http://www.who.is/whois-ip/ip-address/200.80.1.16/";
$lwp = LWP::UserAgent->new();
$lwp -> agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4");
$request = $lwp ->get($url);


 if ($request->content =~ /<br>OrgName:&nbsp;&nbsp;&nbsp;&nbsp(.*)<br>OrgTechEmail:&nbsp;&nbsp/){
print "\n\n";
print "Funciono guasonsito\n";
print $1;
print "Good bye\n";
exit 1;
    } else {

print "EHHHHHHHHH\n";
my $content = $request->content();
print $content;
}
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4



Pero me extrae cualquier cosa y yo solo quiero que extraiga esto:
Código: Seleccionar todo
OrgName:    Latin American and Caribbean IP address Regional Registry
OrgID:      LACNIC
Address:    Rambla Republica de Mexico 6125
City:       Montevideo
StateProv: 
PostalCode: 11400
Country:    UY

ReferralServer: whois://whois.lacnic.net

NetRange:   200.0.0.0 - 200.255.255.255
CIDR:       200.0.0.0/8
NetName:    LACNIC-200
NetHandle:  NET-200-0-0-0-1
Parent:   
NetType:    Allocated to LACNIC
NameServer: NS.LACNIC.NET
NameServer: NS2.LACNIC.NET
NameServer: NS-SEC.RIPE.NET
NameServer: NS2.DNS.BR
NameServer: NS3.AFRINIC.NET
NameServer: SEC3.APNIC.NET
NameServer: TINNIE.ARIN.NET
Comment:    This IP address range is under LACNIC responsibility for further
Comment:    allocations to users in LACNIC region.
Comment:    Please see http://www.lacnic.net/ for further details, or check the
Comment:    WHOIS server located at http://whois.lacnic.net
RegDate:    2002-07-27
Updated:    2009-04-29

OrgTechHandle: LACNIC-ARIN
OrgTechName:   LACNIC Whois Info
OrgTechPhone: 
OrgTechEmail: 

# ARIN WHOIS database, last updated 2009-06-08 19:10
# Enter ? for additional hints on searching ARIN's WHOIS database.


¿Alguien me podría decir cómo modifico mi consulta para que quede así?
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Notapor explorer » 2009-06-09 18:53 @828

Es siempre recomendable usar la salida del propio comando whois, en lugar de interpretar la salida del whois en una página web...

En los sistemas Linux, en la mayoría de las distribuciones, el whois se puede instalar como paquete software aparte (en otros, ya estará instalado).

Desde la línea de comandos, entonces, es fácil la consulta:
Código: Seleccionar todo
explorer@hs-980:~$ whois 200.80.1.16

% Joint Whois - whois.lacnic.net
%  This server accepts single ASN, IPv4 or IPv6 queries

% LACNIC resource: whois.lacnic.net


% Copyright LACNIC lacnic.net
%  The data below is provided for information purposes
%  and to assist persons in obtaining information about or
%  related to AS and IP numbers registrations
%  By submitting a whois query, you agree to use this data
%  only for lawful purposes.
%  2009-06-09 20:55:26 (BRT -03:00)

inetnum:     200.80.0/18
status:      allocated
owner:       IFX NETWORKS COLOMBIA
ownerid:     CO-IFNE-LACNIC
responsible: Julio Cesar Pinto Del Basto
address:     CARRERA 69 # 43B-44 OF. 501, N/A, N/A
address:     57111 - BOGOTA - DC
country:     CO
phone:       +57 1 3693000 [1301]
owner-c:     IFC
tech-c:      INA
abuse-c:     INA
inetrev:     200.80.0/22
nserver:     NS0.IFXNETWORKS.COM
nsstat:      20090605 AA
nslastaa:    20090605
nserver:     NS1.IFXNETWORKS.COM
nsstat:      20090605 AA
nslastaa:    20090605
remarks:     ADDRESSES WITHIN THIS BLOCK ARE NON-PORTABLE
created:     20010717
changed:     20051212

nic-hdl:     IFC
person:      IFX NETWORKS COLOMBIA
e-mail:      [email protected]
address:     CARRERA 69 # 43B-44 OF. 501, n/a, n/a
address:     57111 - BOGOTA - DC
country:     CO
phone:       +57 1 3693000 []
created:     20021021
changed:     20050201

nic-hdl:     INA
person:      IFX Networks Argentina
e-mail:      [email protected]
address:     Av. Belgrano, 1586, Piso 11
address:     C1093AAQ - Buenos Aires -
country:     AR
phone:       +54 11 41042400 []
created:     20020906
changed:     20020906

% whois.lacnic.net accepts only direct match queries.
% Types of queries are: POCs, ownerid, CIDR blocks, IP
% and AS numbers.


Para Perl hay unos cuantos módulos que pueden hacer esa petición de forma directa, como Net::Whois::Raw, por ejemplo.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14477
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Intermedio

¿Quién está conectado?

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

cron