Skip to content

Instantly share code, notes, and snippets.

@grepwood
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save grepwood/c0b2153bddedd397359e to your computer and use it in GitHub Desktop.

Select an option

Save grepwood/c0b2153bddedd397359e to your computer and use it in GitHub Desktop.

Revisions

  1. Michael Dec revised this gist Nov 13, 2014. 1 changed file with 18 additions and 7 deletions.
    25 changes: 18 additions & 7 deletions ssl_test.pl
    Original file line number Diff line number Diff line change
    @@ -5,36 +5,47 @@
    use HTTP::Request;
    use LWP::UserAgent;
    use Net::SSLeay;
    use IO::Socket::SSL;

    my $options=();
    getopts("ha:p:", \%main::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 (defined $main::options{p}) {
    $port = $main::options{p};
    }

    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 $ua = LWP::UserAgent->new();
    my $response = $ua->request($request);

    print $response->status_line . "\n";
    print $response->status_line . "\n";
  2. Michael Dec created this gist Nov 13, 2014.
    40 changes: 40 additions & 0 deletions ssl_test.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Getopt::Std;
    use HTTP::Request;
    use LWP::UserAgent;
    use Net::SSLeay;

    my $options=();
    getopts("ha:p:", \%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";
    exit 0;
    }

    my $satisfied = 0;
    my $address = "";
    my $port = 443;
    if (defined $main::options{a}) {
    $satisfied += 1;
    $address = $main::options{a};
    }
    if (defined $main::options{p}) {
    $port = $main::options{p};
    }

    if(($satisfied & 1) != 1) {
    print "Insufficient arguments. Check with -h what you missed\n";
    exit -1;
    }

    my $request = HTTP::Request->new(GET => "https://$address:$port/");
    my $ua = LWP::UserAgent->new();
    my $response = $ua->request($request);

    print $response->status_line . "\n";