Skip to content

Commit b74dfef

Browse files
committed
yay, csv support
1 parent 7e72944 commit b74dfef

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

domains.txt demo.txt

File renamed without changes.

ssl_check_basic.py

+34-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import socket
44
import ssl
5+
import csv
56
from datetime import datetime
67

78
#
@@ -16,7 +17,7 @@
1617
# "Equifax",
1718
# before 2017 december 1
1819

19-
domain_list_path = 'domains.txt'
20+
domain_list_path = 'demo.txt'
2021
cert_output_path = 'cert_ouput.txt'
2122
cert_status_file = open(cert_output_path, 'w')
2223
bad_issuers = ("Symantec", "GeoTrust", "thawte", "RapidSSL", "VeriSign",
@@ -28,6 +29,19 @@
2829

2930
context = ssl.create_default_context()
3031

32+
output_dictionary = {
33+
"domain": "None",
34+
"valid_until": "None",
35+
"reason": "None",
36+
"checked_on": "None"
37+
}
38+
39+
write = csv.DictWriter(cert_status_file, output_dictionary.keys())
40+
write.writeheader()
41+
"""
42+
let's make a csv, all csvs have headers
43+
"""
44+
3145

3246
def datify_date(the_date):
3347
# the_date = the_date.replace(tzinfo, "None")
@@ -78,7 +92,8 @@ def check_cert(domain):
7892
result_dictionary = {
7993
"domain": domain,
8094
"issuer": issuer,
81-
"valid_until": valid_until
95+
"valid_until": valid_until,
96+
"checked_on": now_date.strftime("%Y-%m-%d")
8297
}
8398
valid_until = datify_date(result_dictionary['valid_until'])
8499
bad_list = []
@@ -95,23 +110,33 @@ def check_cert(domain):
95110
"{} {} {}".format(
96111
"less than", int(
97112
check_expiration_date(valid_until)),
98-
"days left")
113+
"days left"),
114+
"checked_on":
115+
now_date.strftime("%Y-%m-%d")
99116
}
100-
cert_status_file.write(str(reasons) + '\n')
117+
print(reasons)
118+
write.writerow(reasons)
101119
cert_status_file.flush()
102120
if any(bad in issuer for bad in bad_issuers):
103121
reasons = {
104122
"domain": domain,
105123
"valid_until": valid_until.strftime("%Y-%m-%d"),
106-
"reason": "issuer"
124+
"reason": "issuer",
125+
"checked_on": now_date.strftime("%Y-%m-%d")
107126
}
108-
cert_status_file.write(str(reasons) + '\n')
127+
print(reasons)
128+
write.writerow(reasons)
109129
cert_status_file.flush()
110-
print(reasons)
111130
except Exception as e:
112-
fail = {"domain": domain, "valid_until": "none", "reason": e}
131+
fail = {
132+
"domain": domain,
133+
"valid_until": "none",
134+
"reason": e,
135+
"checked_on": now_date.strftime("%Y-%m-%d")
136+
}
113137
print(fail)
114-
cert_status_file.write(str(fail) + '\n')
138+
write.writerow(fail)
139+
cert_status_file.flush()
115140
return
116141

117142

0 commit comments

Comments
 (0)