blob: 34c7a0656a144ac86bc2e4591810b6c2101c7fe0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
from parseEml import parseEml
import os
def read_spf(email_path):
mail = parseEml(email_path)
auth_result = mail.get_auth_results()
if auth_result and "spf=" in auth_result:
tmp_list = auth_result.split("spf=")
spf_result=tmp_list[1].split(" ")[0]
else:
spf_result=None
return spf_result
#输入:邮件文件夹路径
#输出:spf认证结果统计dict
def spf_count(email_folder):
spf_count_dict={}
files = os.listdir(email_folder)
print(email_folder+":\ntotal: "+str(len(files)))
for file in files: # 遍历文件夹
if file == "duplicate":
continue
spf_result=read_spf(email_folder+"/"+file)
if spf_result in spf_count_dict:
spf_count_dict[spf_result]+=1
else:
spf_count_dict[spf_result]=1
print(spf_count_dict)
#输入:中间域名列表
#输出:域名出现次数统计结果
def inter_domain_count(inter_domain_file):
count_dict={}
with open(inter_domain_file,"r",encoding="utf-8") as f:
line = f.readline()
while line:
line=line.strip()
if line in count_dict:
count_dict[line]+=1
else:
count_dict[line]=1
line = f.readline()
a = sorted(count_dict.items(), key=lambda x: x[1], reverse=True)
print(a)
if __name__ == "__main__":
inter_domain_count("inter_domain.txt")
|