在启用了 IPv6 的 Windows 10 下使用 Strawberry Perl 5.30.1 时,由于 Perl 的 DNS 解析器中似乎存在错误,因此无法正确解析带有端口号的 URL。
对于以下测试,我们有一个简单的 Web 服务器,侦听端口 8810 的所有接口。
端口 12345 确实NOT托管任何东西。
以下是我们用于复制的脚本:
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";
当使用 5.28.0 执行时,我得到了正确的响应
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.
但是,当尝试使用 5.30.1 时,无论是否确实有端口打开,我都会得到错误地址
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.
请注意,如果我们直接提供 IPv4 地址,5.30.1 仍然能够实际请求信息。此外,对于不解析为 IPv6 而仅解析为 IPv4 的 DNS,5.30.1 似乎没有问题。
还有其他人有这个问题吗?如果是的话,这被认为是一个错误还是我们只是以某种错误的方式使用 Perl?
UPDATE:我发现了另一块似乎有贡献的拼图:
到目前为止,我们仅在我们的公司 Windows 机器上进行了尝试,所有机器在 Perl 5.30.1 和 5.30.2 上都有相同的行为。不过,我现在也尝试了我的私人 Windows 10,它成功了。
然后我深入研究了 IPv4 和 IPv6,并得出了这篇来自微软的知识库文章:https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users
底线:我在注册表中设置 Windows 应该更喜欢 IPv4 而不是 IPv6(设置 0x20),重新启动 - 它在我的公司 Windows 10 上运行!
显然我们有一些与 perl 相关的设置,但似乎仍然有一个问题:当尝试访问无法访问的本地主机端口时,我们仍然收到“错误地址”错误而不是“连接被拒绝”,这意味着仍然有一些错误解析了我们的 dns:port 字符串。
另外,我希望 Perl 现在能够完全支持 IPv6。