gpt4 book ai didi

perl - 使用端口访问 IPv6 可解析 URL(例如 localhost :12345) results in Bad Address in Strawberry Perl 5. 30.1

转载 作者:行者123 更新时间:2023-12-03 20:54:10 25 4
gpt4 key购买 nike

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

对于以下测试,我们有一个简单的网络服务器在端口 8810 上监听所有接口(interface)。

端口 12345 执行 不是 托管任何东西。

以下是我们用于复制的脚本:

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?

更新:我发现了另一个似乎有帮助的难题:

到目前为止,我们只在公司的 windows 机器上进行了尝试,所有机器在 Perl 5.30.1 和 5.30.2 上都有相同的行为。但是,我现在也尝试了我的私有(private) Windows 10,它工作正常。

然后我挖掘了一些关于 IPv4 和 IPv6 的知识,并提出了这篇来自 microsoft 的知识库文章: https://support.microsoft.com/en-us/help/929852/guidance-for-configuring-ipv6-in-windows-for-advanced-users

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

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

另外,我希望 perl 现在可以完全支持 IPv6。

最佳答案

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

这似乎在这里工作正常,从您的 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.

关于perl - 使用端口访问 IPv6 可解析 URL(例如 localhost :12345) results in Bad Address in Strawberry Perl 5. 30.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61455027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com