-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspf.py
140 lines (115 loc) · 3.49 KB
/
spf.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
import os
import sys
from src import figlet
from src import colors as co
# --------------- Functions --------------- #
def printintro():
co.printout(figlet.ascii_work, co.BLUE)
co.printout("\n[WRN]",co.YELLOW)
co.printout(" Use with caution.You are responsible for your actions\n")
co.printout("[WRN]",co.YELLOW)
co.printout(" Developer assume no liability and are not responsible for any misuse\n\n")
def spf_bulk(domain,read=" "):
tool= "nslookup -type=txt {} "
com= tool.format(domain)
run=os.popen(com)
read=run.read()
if '"v=spf1' in read:
res0="[SPF record found] {}"
res1=res0.format(domain)
co.printout(res1,co.GREEN)
return res1
elif "text" in read:
res01="[SPF record not found] {}"
res1=res01.format(domain)
co.printout(res1,co.YELLOW)
return res1
else:
res0="An error occured,skipping {} "
res1=res0.format(domain)
co.printout(res1,co.RED)
def spf_single(domain):
tool= "nslookup -type=txt {} "
com= tool.format(domain)
run=os.popen(com)
read=run.read()
if '"v=spf1' in read:
co.printout("SPF record found",co.GREEN)
elif "text" in read:
co.printout("SPF record not found",co.YELLOW)
else:
co.printout("An error occured!!",co.RED)
def read_write(path1,path2,length):
f=open(path1,"r")
str1= " "
O=open(path2,"w")
for i in range(length):
str1=f.readline()
result=spf_bulk(str1)
if result!=None:
O.write(result)
else:
pass
f.close()
O.close()
def read_print(path1,length):
f=open(path1,"r")
str1= " "
for i in range(length):
str1=f.readline()
spf_bulk(str1)
f.close()
def len_f(path1):
f=open(path1,"r")
str1=f.readlines()
length=len(str1)
return length
f.close()
# -------------- Main -------------- #
args=len(sys.argv)
argv=sys.argv
try:
if args==1:
print()
print('''-h, --help for Help section''')
elif args==2 and argv[1]=="-h" or argv[1]=="--help":
print()
help='''Usage: python3 spf.py [-h] [-v] [-d] [-l] domain_name/input_file [-o] output_file
------------------------------------------------------------------------------------------------
Options:
-h, --help Help section
-v, --version Show version
-d, --domain for single domain
-l, --inputfile Input file of domain name (support only ".txt" extension)
-o, --outputfile Output file name (support only ".txt" extension)
------------------------------------------------------------------------------------------------
'''
co.printout(help,co.CYAN)
elif args==2 and argv[1]=="-v" or argv[1]=="--version":
co.printout('Version --> 1.0',co.CYAN)
elif args==3 and argv[1]=="-d" or argv[1]=="--domain":
domain=argv[2]
printintro()
spf_single(domain)
elif args==3 and argv[1]=="-l" or argv[1]=="--inputfile":
path1=argv[2]
printintro()
try:
length=len_f(path1)
read_print(path1,length)
except (FileNotFoundError,FileExistsError):
co.printout("File Not Found Error!!",co.RED)
elif args==5 and argv[1]=="-l" or argv[1]=="--inputfile" and argv[3]=="-o" or argv[3]=="--outputfile":
path1=argv[2]
path2=argv[4]
printintro()
try:
length=len_f(path1)
read_write(path1,path2,length)
except (FileNotFoundError,FileExistsError):
co.printout("File Not Found Error!!",co.RED)
else:
co.printout("Invalid operation!!",co.RED)
except IndexError:
co.printout("Invalid operation!!",co.RED)