Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable IPv6 support in LWP?

Tags:

perl

ipv6

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)?
like image 740
knorv Avatar asked Feb 06 '10 22:02

knorv


People also ask

How do I enable IPv6 connectivity?

Right-click your network connection. Select Properties. Scroll to Internet Protocol version 6. Check the Internet Protocol Version 6 (TCP/IPv6) box.

How do I know if IPv6 is enabled?

For wired connection through a router, right-click “Ethernet”, and for wireless connection right-click “Wi-Fi”, and then click “Status”. Click “Details”. If you see an IP address for IPv6 within the window marked with a red box, you are connected to the IPv6 network.

How do I change IPv4 to IPv6?

To convert Internet Protocol 4 (IPv4) to Internet Protocol 6 (IPv6), perform the following steps. Open the tool: IPv4 to IPv6 converter. Enter any valid IPv4 address, and click on the "Convert to IPv6" button. The tool will process your request and provide you the converted IPv6 address.


2 Answers

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' );
like image 100
cjm Avatar answered Oct 14 '22 12:10

cjm


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"

like image 25
H. Green Avatar answered Oct 14 '22 11:10

H. Green