N
N
networkSolutions2015-02-18 13:30:27
Perl
networkSolutions, 2015-02-18 13:30:27

Parsing ip from 2ip to perl?

Help with a simple example of parsing ip from 2ip.ru to perl

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
krypt3r, 2015-02-18
@krypt3r

Something like

my ($ip) = $page_content =~ m|<span>\s*Ваш IP адрес:\s*</span>.*?<big.*?>((?:\d{1,3}\.){3}\d{1,3})</big>|ism;

D
dionys, 2015-02-19
@dionys

perl -Mojo -E 'say g("http://2ip.ru/")->dom("#d_clip_button")->text'

R
Rozello, 2015-03-29
@Rozello

#!/usr/bin/env perl

# Включаем варнинги и ужесточение синтаксиса
use strict;
use warnings;

# Включаем библиотеку для работы с http
use LWP::Simple;

# Качаем страницу, если не удалось пркращаем работу
my $page = get('http://2ip.ru/') or die "Can't get page!";

# Парсим IP ргуляркой если не удалось прекращаем работу
my ($ip) = ($page =~ m!(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})!) or die "Can't pars IP!";

# Выводим IP
print 'You IP: '.$ip."\n";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question