/
main.py
206 lines (164 loc) · 5.41 KB
/
main.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env python3
#/***************************************************************************//**
# @file main.py
#
# @author Black-Blade
# @brief log.py
# @date 13.1.2021
# @version 0.0.1 Doxygen style eingebaut und erstellen dieser File
# @see https://tools.ietf.org/html/rfc1035
# https://tools.ietf.org/html/rfc7858
# https://tools.ietf.org/html/rfc8484
#*******************************************************************************/
from log import setup_log,main_log
from log import logging
import subprocess
import sys
import time
# IMPORT MY STANDRT CLASS
from config import Config
from dropdns import DNS_DROP
#Import CLASS OF DNS UDP(INPUT)
if Config.I_UDPENABLE==True:
from i_udp import Input_UDP
#Import CLASS OF DNS TCP(INPUT)
if Config.I_TCPENABLE==True:
from i_tcp import Input_TCP
#Import CLASS OF DNS OVER TLS(INPUT)
if Config.I_DOTENABLE==True:
from i_dot import Input_DOT
#Import CLASS OF DNS OVER HTTPS(INPUT)
if Config.I_DOHENABLE==True:
from i_doh import Input_DOH
#Import CLASS OF DNS BY UDP(OUTPUT)
if Config.O_UDPENABLE==True:
from o_udp import OUTPUT_UDP
#Import CLASS OF DNS BY UDP(OUTPUT)
if Config.O_TCPENABLE==True:
from o_tcp import OUTPUT_TCP
#Import CLASS OF DNS BY DOH(OUTPUT)
if Config.O_DOHENABLE==True:
from o_doh import OUTPUT_DOH
#Import CLASS OF DNS BY DOT(OUTPUT)
if Config.O_DOTENABLE==True:
from o_dot import OUTPUT_DOT
# POINTER OF OUTPUT
output =None
# POINTER OF DROPDNS
dropdns =None
#/*******************************************************************************
# @author Black-Blade
# @brief test the ip of contry
# please install geoip-bin in systen
# @date 06.03.2021
# @param [host(ip)]
# @return [status(True,False),text]
# @version 0.0.1 Doxygen style eingebaut und erstellen dieser File
# @see
# *******************************************************************************/
def geoip(host):
logging.debug ("")
# TEST IP IN GEOIP IN OS
process = subprocess.run(['geoiplookup', host], capture_output=True)
data = str(process.stdout)
if data.find("IP Address not found") >= 0:
return [True,str(host)]
elif data.find("Germany") >= 0:
return [True,"from Germany"]
return [False,"Not from Germany"]
#/*******************************************************************************
# @author Black-Blade
# @brief all data coming her bevor go to select output
# @date 06.03.2021
# @param [txdata(dns request)]
# @return [isblock,rxdata,blockname,dname]
# @version 0.0.1 Doxygen style eingebaut und erstellen dieser File
# @see
# *******************************************************************************/
def switch(txdata):
logging.debug ("")
# NO OUTPUT SET RETURN NONE
if output is None:
return None
# TEST DOMIN IN FILTER
if dropdns is None:
return None
isblock,rxblock,blockname,dname =dropdns.drop(txdata)
if isblock==True:
rxdata= rxblock
else:
rxdata = output.send(txdata)
return [isblock,rxdata,blockname,dname]
#/*******************************************************************************
# @author Black-Blade
# @brief mainprogramm start
# @date 06.03.2021
# @param
# @return
# @version 0.0.1 Doxygen style eingebaut und erstellen dieser File
# @see
# *******************************************************************************/
if __name__ == "__main__":
setup_log()
main_log()
if Config.O_UDPENABLE == True and \
Config.O_TCPENABLE == True and \
Config.O_DOHENABLE == True and \
Config.O_DOTENABLE==True:
logging.error("OS error: to many outputs set")
quit()
if Config.O_UDPENABLE == False and \
Config.O_TCPENABLE == False and \
Config.O_DOHENABLE == False and \
Config.O_DOTENABLE== False :
logging.error("OS error: no outputs set")
quit()
if Config.I_UDPENABLE == False and \
Config.I_TCPENABLE == False and \
Config.I_DOTENABLE == False and \
Config.I_DOHENABLE== False :
logging.error("OS error: no input set")
quit()
dropdns =DNS_DROP()
#ENABLE CLASS OF DNS BY UDP(OUTPUT)
if Config.O_UDPENABLE==True:
output= OUTPUT_UDP()
#ENABLE CLASS OF DNS BY TCP(OUTPUT)
if Config.O_TCPENABLE==True:
output= OUTPUT_TCP()
#ENABLE CLASS OF DNS BY DOH(OUTPUT)
if Config.O_DOHENABLE==True:
output= OUTPUT_DOH()
#ENABLE CLASS OF DNS BY DOT(OUTPUT)
if Config.O_DOTENABLE==True:
output= OUTPUT_DOT()
#ENABLE CLASS OF DNS UDP (INPUT)
if Config.I_UDPENABLE==True:
i_udp=Input_UDP(switch,geoip)
i_udp.init()
#ENABLE CLASS OF DNS TCP (INPUT)
if Config.I_TCPENABLE==True:
i_tcp=Input_TCP(switch,geoip)
i_tcp.init()
#ENABLE CLASS OF DNS OVER TLS (INPUT)
if Config.I_DOTENABLE==True:
i_dot=Input_DOT(switch,geoip)
i_dot.init()
#Import CLASS OF DNS OVER HTTPS(INPUT)
if Config.I_DOHENABLE==True:
i_doh=Input_DOH(switch,geoip)
i_doh.init()
while True:
time.sleep(10)
#LOGS CLASS OF DNS UDP (INPUT)
if Config.I_UDPENABLE==True:
i_udp.logs()
#LOGS CLASS OF DNS TCP (INPUT)
if Config.I_TCPENABLE==True:
i_tcp.logs()
#LOGS CLASS OF DNS OVER TLS (INPUT)
if Config.I_DOTENABLE==True:
i_dot.logs()
#LOGS CLASS OF DNS OVER HTTPS(INPUT)
if Config.I_DOHENABLE==True:
i_doh.logs()