Perl WWW::Mechanize:如何独立于 URL 指定目标 IP 地址?

Perl WWW::Mechanize: How can I specify the destination IP address independently of the URL?

我想使用 Perl www::mechanize 连接到网络服务器并请求资源。例如。 http://www.my.domain/test.html。但我想在 URL.

中独立于主机名指定 IP 地址

例如:www.my.domain 解析为 1.1.1.1,但我想连接到 2.2.2.2。

我想这样做是为了测试负载平衡器后面的多个 Web 服务器。

使用LWP::UserAgent::DNS::Hosts;

与 WWW::Mechanize 配合使用效果很好。

use LWP::UserAgent::DNS::Hosts;
use WWW::Mechanize;

LWP::UserAgent::DNS::Hosts->register_host('www.my.domain' => '2.2.2.2');
LWP::UserAgent::DNS::Hosts->enable_override;

my $mech = WWW::Mechanize->new;
$mech->get('http://www.my.domain/test.html'); # connects to 2.2.2.2