Advertisement
opexxx

cert_checker.py

Jul 26th, 2014
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import M2Crypto
  2. import sys, ssl, datetime
  3.  
  4. def printlog(host, message):
  5.   now = datetime.datetime.now()
  6.   datestr = now.strftime("%Y-%m-%d %H:%M:%S")
  7.   print '%s|server=\'%s\'|ssl_expires=\'%s\'' % (datestr, host, message)
  8.  
  9. if len(sys.argv) != 3:
  10.   printlog('', 'no host or port specified.')
  11.   sys.exit(1)
  12. else:
  13.   srvr = sys.argv[1]
  14.   port = sys.argv[2]
  15.  
  16. host = srvr+':'+str(port)
  17. try:
  18.   cert = ssl.get_server_certificate((srvr, int(port)))
  19.   x509 = M2Crypto.X509.load_cert_string(cert)
  20.   printlog(host, str(x509.get_not_after()))
  21. except Exception as e:
  22.   printlog(host, str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement