Sha256: d057868ee790a0e5915e00ea8662d1743c26dcda9916ecc6d5973a3a34e9b165

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

#! /usr/bin/env ruby

require 'cert_checker'
require 'optparse'

options = { hosts: [] }

parser = OptionParser.new do |opts|
  opts.banner = "cert_checker [-d domain_or_ip] [-f hosts_file]"
  opts.version = CertChecker::VERSION

  opts.on('-d domain', "host name, example google.com. more host: -d h1.com -d h2.com") do |host|
    options[:hosts] << host
  end

  opts.on(
    '-f file', "hosts file, split hosts by new line, and ignore line whice start by # and empt line"
  ) do |file|
    options[:file] = file
  end
end

parser.parse!

hosts = options[:hosts]
if (file = options[:file]) && File.exists?(file)
  hosts += File.readlines(file).map(&:strip).select { |host| host.size > 0 && host[0] != '#' }
end

puts parser.help if hosts.empty?

format = "%-14s %-35s %-20s %10s %s (%s)"
hosts.each do |host|
  begin
    status, host, issuer, expired, desc, alpn_protocol = CertChecker.check(host)
    expired = expired.strftime('%F') if expired
    desc = desc.to_s + ' days' if desc.to_s =~ /^\d+$/
    alpn_protocol ||= 'No ALPN'
    puts format % [status, host, issuer, expired, desc, alpn_protocol]
  rescue CertChecker::Error => e
    puts format % ['error', host, e.message, nil, nil, nil]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cert_checker-0.1.3 exe/cert_checker