Skip to content

Instantly share code, notes, and snippets.

@grepwood
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grepwood/c0b2153bddedd397359e to your computer and use it in GitHub Desktop.
Save grepwood/c0b2153bddedd397359e to your computer and use it in GitHub Desktop.
Tests SSL connection with specified host and port
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use HTTP::Request;
use LWP::UserAgent;
use Net::SSLeay;
use IO::Socket::SSL;
my $options=();
getopts("ha:p:c:", \%main::options);
if (defined $main::options{h}) {
print "This program verifies SSL on a host\n";
print " -h see this message\n";
print " -a address of the host\n";
print " -p port (optional)\n";
print " -c path to SSL cert (optional)\n";
exit 0;
}
my $satisfied = 0;
my $address = "";
my $port = 443;
my $cert_filename = "";
if (defined $main::options{a}) {
$satisfied += 1;
$address = $main::options{a};
}
if(($satisfied & 1) != 1) {
print "Insufficient arguments. Check with -h what you missed\n";
exit -1;
}
if (defined $main::options{p}) {
$port = $main::options{p};
}
my $ua = "";
if (defined $main::options{c}) {
$cert_filename = $main::options{c};
$ua = LWP::UserAgent->new(
verify_hostname => 0,
SSL_ca_file => "$cert_filename",
);
} else {
$ua = LWP::UserAgent->new();
}
my $request = HTTP::Request->new(GET => "https://$address:$port/");
my $response = $ua->request($request);
print $response->status_line . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment