使用端口(例如 localhost:12345)访问 IPv6 可解析 URL 会导致 Strawberry Perl 5.30.1 中的地址错误 [英] Accessing IPv6 resolvable URL with port (e.g. localhost:12345) results in Bad Address in Strawberry Perl 5.30.1

查看:79
本文介绍了使用端口(例如 localhost:12345)访问 IPv6 可解析 URL 会导致 Strawberry Perl 5.30.1 中的地址错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启用了 IPv6 的 Windows 10 下使用草莓 perl 5.30.1 时,由于 Perl 的 DNS 解析器中似乎存在错误,因此无法正确解析带有端口号的 URL.

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.

在下面的测试中,我们有一个简单的网络服务器监听所有接口的 8810 端口.

For the following test, we have a simple webserver listening on Port 8810 for all interfaces.

端口 12345 托管任何内容.

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";

用 5.28.0 执行时,得到正确响应

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.

但是,当尝试使用 5.30.1 时,我得到了错误地址,无论是否真的有端口打开

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.

请注意,如果我们直接提供 IPv4 地址,5.30.1 仍然能够实际请求信息.此外,对于不能解析为 IPv6 而只能解析为 IPv4 的 DNS,5.30.1 似乎没有问题.

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.

其他人有没有这个问题,如果有,这被认为是一个错误还是我们只是以某种错误的方式使用了 perl?

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:

到目前为止,我们只在我们公司的 Windows 机器上尝试过,所有机器在 Perl 5.30.1 和 5.30.2 上都具有相同的行为.但是,我现在也尝试了我的私人 Windows 10,并且成功了.

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.

然后我挖掘了一些关于 IPv4 和 IPv6 的内容,并从微软提出了这篇知识库文章:https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows- 高级用户

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

底线:我在注册表中设置 Windows 应该更喜欢 IPv4 而不是 IPv6(设置 0x20),重新启动 - 它在我的公司 Windows 10 上运行!

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!

显然我们有一些与 perl 相关的设置,但似乎仍然存在一个问题:当尝试访问无法访问的本地主机端口时,我们仍然收到错误地址"错误而不是连接被拒绝",这意味着仍有一些错误解析了我们的 dns:port 字符串.

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.

此外,我希望 perl 现在完全支持 IPv6.

Also, I'd expect perl to fully support IPv6 by now.

推荐答案

我在 KVM 虚拟机(在 Ubuntu 20.04 上)中尝试过这个,运行 Windows 10、Strawberry Perl 5.30.1、XAMPP 7.4.5,虚拟主机在 8080 上监听,根据控制面板中的网络和 Internet 设置启用 IPv4 和 IPv6.

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.

这似乎在这里工作正常,您的 test2.pl 脚本的输出是:

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.

这篇关于使用端口(例如 localhost:12345)访问 IPv6 可解析 URL 会导致 Strawberry Perl 5.30.1 中的地址错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆