简体   繁体   中英

How do I enable IPv6 support in LWP?

The following code ...

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);
}

.. will fail with ..

500 Can't connect to <hostname> (Bad hostname '<hostname>')

.. if the hostname in $url is an IPv6 only address (that is: presence of an AAAA record, but no A record).

My questions are:

  • How do I enable IPv6 support in LWP?
  • How do I configure LWP's settings for "prefer-IPv4-over-IPv6" ( A vs. AAAA ) / "prefer-IPv6-over-IPv4" ( AAAA vs. A )?

It looks like you just need to use Net::INET6Glue::INET_is_INET6 . To quote its example:

 use Net::INET6Glue::INET_is_INET6;
 use LWP::Simple;
 print get( 'http://[::1]:80' );
 print get( 'http://ipv6.google.com' );

I believe you'll have to change the module to use the IPV6 net module. By default it does not have this enabled: http://eintr.blogspot.com/2009/03/bad-state-of-ipv6-in-perl.html . I don't believe there is something as simple as "prefer-ipv6"

Debian Wheezy (perl 5.14)

Work nice:

use LWP::Simple;
print get( 'http://ip6-localhost:80' );

Not working (1)

use LWP::Simple;
print get( 'http://[::1]:80' );

Not working (2) [Return: Bad hostname ]

use LWP::Simple;
$ua = new LWP::UserAgent();
my $req = new HTTP::Request("GET", "http://[::1]/");
my $res = $ua->request($req);

Not working (3) [Return: Connection refused ]

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, if you don't need IPv6 address in http request, it's fine. :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM