Perl 语法 Net::SSLeay "perl -e"字符串中的变量赋值(它本身在脚本中)



以下摘录来自https.monitor freeware mon监视程序。

$result = `$perl -e'use Net::SSLeay ; Net::SSLeay::SSLeay_add_ssl_algorithms() ; print join("$field_delim",Net::SSLeay::get_https("$site", "$port", "$path"))'`;

正在监视的某些HTTPS服务器与autodectect和/或tls的OpenSSL(NET :: SSLEAY)不兼容。

以下从命令行按预期工作,并明确将ssl_version更改为3:

perl -e 'use Net::SSLeay; Net::SSLeay::SSLeay_add_ssl_algorithms() ; $Net::SSLeay::ssl_version = 3 ; print join("<>",Net::SSLeay::get_https("server.domain.internal", "443", "/"))'

我无法在https.monitor Perl文件中的原始行中使用它。如上所述,Perl将告知以下错误:

Can't modify constant item in scalar assignment at -e line 1, near "3 ;"

我已经尝试了各种语法来使这一行进行编译和SSL_Version设置,但是我似乎不能一次同时发生。使用NET :: SSLEAY :: SSL_VERSION变量分配的" =>"语法,我可以将其进行编译,但该设置似乎没有"取"。我已经使用了$ net :: ssleay :: ssl_version和" $ net :: ssleay :: ssl_version",卷曲在变量上等等,但是我无法使其正常工作。

" net :: ssleay :: ssl_version = 3"的语法应该是什么?

my $result = `perl -e'... $Net::SSLeay::ssl_version = 3; ...'`;

,这太容易了,但是弄错了。您可以使用String :: ShellQuote的shell_quote

use String::ShellQuote qw( shell_quote );
my $cmd = shell_quote(
    $perl,
    -e => <<'__EOI__',
        use Net::SSLeay;
        my ($field_delim, $site, $port, $path) = @ARGV;
        Net::SSLeay::SSLeay_add_ssl_algorithms();
        $Net::SSLeay::ssl_version = 3;
        print join($field_delim, Net::SSLeay::get_https($site, $port, $path));
__EOI__
    '--',
    $field_delim, $site, $port, $path,
);
my $result = `$cmd`;

您可以完全使用IPC :: System :: Simple的capturex

完全避免使用外壳。
use IPC::System::Simple qw( capturex );
my @cmd = (
    $perl,
    -e => <<'__EOI__',
        use Net::SSLeay;
        my ($field_delim, $site, $port, $path) = @ARGV;
        Net::SSLeay::SSLeay_add_ssl_algorithms();
        $Net::SSLeay::ssl_version = 3;
        print join($field_delim, Net::SSLeay::get_https($site, $port, $path));
__EOI__
    '--',
    $field_delim, $site, $port, $path,
);
my $result = capturex(@cmd);

奖金:capturex为您检查错误!使用前两种方法,您至少需要以下内容:

die $! if $? == -1;
die "Killed by signal ".($? & 127) if $? & 127;
die "Exited with error ".($? >> 8) if $? >> 8;

相关内容

最新更新