Last active
August 29, 2015 14:09
-
-
Save grepwood/c0b2153bddedd397359e to your computer and use it in GitHub Desktop.
Tests SSL connection with specified host and port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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