2
2
3
3
import socket
4
4
import ssl
5
+ import csv
5
6
from datetime import datetime
6
7
7
8
#
16
17
# "Equifax",
17
18
# before 2017 december 1
18
19
19
- domain_list_path = 'domains .txt'
20
+ domain_list_path = 'demo .txt'
20
21
cert_output_path = 'cert_ouput.txt'
21
22
cert_status_file = open (cert_output_path , 'w' )
22
23
bad_issuers = ("Symantec" , "GeoTrust" , "thawte" , "RapidSSL" , "VeriSign" ,
28
29
29
30
context = ssl .create_default_context ()
30
31
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
+
31
45
32
46
def datify_date (the_date ):
33
47
# the_date = the_date.replace(tzinfo, "None")
@@ -78,7 +92,8 @@ def check_cert(domain):
78
92
result_dictionary = {
79
93
"domain" : domain ,
80
94
"issuer" : issuer ,
81
- "valid_until" : valid_until
95
+ "valid_until" : valid_until ,
96
+ "checked_on" : now_date .strftime ("%Y-%m-%d" )
82
97
}
83
98
valid_until = datify_date (result_dictionary ['valid_until' ])
84
99
bad_list = []
@@ -95,23 +110,33 @@ def check_cert(domain):
95
110
"{} {} {}" .format (
96
111
"less than" , int (
97
112
check_expiration_date (valid_until )),
98
- "days left" )
113
+ "days left" ),
114
+ "checked_on" :
115
+ now_date .strftime ("%Y-%m-%d" )
99
116
}
100
- cert_status_file .write (str (reasons ) + '\n ' )
117
+ print (reasons )
118
+ write .writerow (reasons )
101
119
cert_status_file .flush ()
102
120
if any (bad in issuer for bad in bad_issuers ):
103
121
reasons = {
104
122
"domain" : domain ,
105
123
"valid_until" : valid_until .strftime ("%Y-%m-%d" ),
106
- "reason" : "issuer"
124
+ "reason" : "issuer" ,
125
+ "checked_on" : now_date .strftime ("%Y-%m-%d" )
107
126
}
108
- cert_status_file .write (str (reasons ) + '\n ' )
127
+ print (reasons )
128
+ write .writerow (reasons )
109
129
cert_status_file .flush ()
110
- print (reasons )
111
130
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
+ }
113
137
print (fail )
114
- cert_status_file .write (str (fail ) + '\n ' )
138
+ write .writerow (fail )
139
+ cert_status_file .flush ()
115
140
return
116
141
117
142
0 commit comments