问题
When using strawberry perl 5.30.1 under Windows 10 with IPv6 enabled, URLs with Portnumbers cannot be resolved properly due to what appears to be a bug in the DNS parser of Perl.
For the following test, we have a simple webserver listening on Port 8810 for all interfaces.
Port 12345 does NOT host anything.
Following is the script we use for reproduction:
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $result=$ua->get("http://localhost:8810/");
print "(DNS Expect: Success) The server responded with Status Code ".$result->status_line.".\n";
$result=$ua->get("http://localhost:12345/");
print "(DNS Expect: Failure) The server responded with Status Code ".$result->status_line.".\n";
$result=$ua->get("http://127.0.0.1:8810/");
print "(IPv4 Expect: Success) The server responded with Status Code ".$result->status_line.".\n";
When being executed with 5.28.0, I get the correct response
C:\perl-test>strawberry-perl-5-28-0-original\perl\bin\perl.exe test2.pl
(DNS Expect: Success) The server responded with Status Code 200 OK.
(DNS Expect: Failure) The server responded with Status Code 500 Can't connect to localhost:12345 (No connection could be made because the target machine actively refused it.).
(IPv4 Expect: Success) The server responded with Status Code 200 OK.
However, when trying with 5.30.1, I get Bad Address, regardless of whether there actually is a port open or not
C:\perl-test>strawberry-perl-5-30-1-original\perl\bin\perl.exe test2.pl
(DNS Expect: Success) The server responded with Status Code 500 Can't connect to localhost:8810 (Bad address).
(DNS Expect: Failure) The server responded with Status Code 500 Can't connect to localhost:12345 (Bad address).
(IPv4 Expect: Success) The server responded with Status Code 200 OK.
Note how 5.30.1 still is able to actually request the information if we provide the IPv4 address directly. Also, for DNS that do not resolve to IPv6 but only IPv4, 5.30.1 does not seem to have an issue.
Does anyone else have this issue and if so is this considered a bug or do we just use perl in some wrong way?
UPDATE: I found another piece of the puzzle that seems to contribute:
We tried so far only on our corporate windows machines, all machines had the same behavior with Perl 5.30.1 and 5.30.2. However, I now also tried my private Windows 10 and it worked.
Then I dug a bit about IPv4 and IPv6 and came up with this knowledge base article from microsoft: https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users
Bottom line: I set in the registry that Windows should prefer IPv4 over IPv6 (Setting 0x20), rebooted - and it worked on my corporate windows 10!
So apparently we have some setting that screws with perl but there still seems to be a catch: When trying to access a localhost port that is not reachable, we still get the "Bad address" error instead of "Connection refused", meaning there is still something that is misparsing our dns:port string.
Also, I'd expect perl to fully support IPv6 by now.
回答1:
I tried this in KVM virtual machine (on Ubuntu 20.04), running Windows 10, Strawberry Perl 5.30.1, XAMPP 7.4.5 with virtual host listening on 8080, both IPv4 and IPv6 are enabled according to the Network and Internet settings in the control panel.
This seems to work fine here, output from your test2.pl
script is:
(DNS Expect: Success) The server responded with Status Code 200 OK.
(DNS Expect: Failure) The server responded with Status Code 500 Can't connect to localhost:12345 (No connection could be made because the target machine actively refused it.).
(IPv4 Expect: Success) The server responded with Status Code 200 OK.
来源:https://stackoverflow.com/questions/61455027/accessing-ipv6-resolvable-url-with-port-e-g-localhost12345-results-in-bad-ad