Come posso abilitare il supporto IPv6 in LWP?
Domanda
Il seguente codice ...
my $user_agent = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => $url);
my $response = $user_agent->request($request);
if ($response->is_success) {
print "OK\n";
} else {
die($response->status_line);
}
..riuscirà con ..
500 Can't connect to <hostname> (Bad hostname '<hostname>')
..se il nome è in $url è un solo IPv6 indirizzo (che è:presenza di un AAAA
record, ma non A
record).
Le mie domande sono:
- Come posso abilitare il supporto IPv6 in LWP?
- Come faccio a configurare LWP impostazioni per "preferisce-IPv4-over-IPv6" (
A
vsAAAA
) / "preferisco-IPv6 su IPv4" (AAAA
vsA
)?
Soluzione
Sembra che non vi resta che utilizzare Net :: :: INET6Glue INET_is_INET6 . Per citare il suo esempio:
use Net::INET6Glue::INET_is_INET6;
use LWP::Simple;
print get( 'http://[::1]:80' );
print get( 'http://ipv6.google.com' );
Altri suggerimenti
Credo che si dovrà cambiare il modulo di utilizzare il modulo di rete IPv6. Per impostazione predefinita, non ha questa abilitato: http : //eintr.blogspot.com/2009/03/bad-state-of-ipv6-in-perl.html . Non credo che ci sia qualcosa di semplice come "preferire-ipv6"
Debian Wheezy (perl 5.14)
Lavoro nice:
use LWP::Simple;
print get( 'http://ip6-localhost:80' );
Non funziona (1)
use LWP::Simple;
print get( 'http://[::1]:80' );
Non funziona (2) [Ritorno: Bad hostname]
use LWP::Simple;
$ua = new LWP::UserAgent();
my $req = new HTTP::Request("GET", "http://[::1]/");
my $res = $ua->request($req);
Non funziona (3) [Ritorno: Connessione rifiutata]
use Net::INET6Glue::INET_is_INET6;
use LWP::Simple;
$ua = new LWP::UserAgent();
my $req = new HTTP::Request("GET", "http://[::1]/");
my $res = $ua->request($req);
Soo, se non avete bisogno di un indirizzo IPv6 nella richiesta http, va bene.:(