Added config

master
Ruakij 3 years ago
parent bbeac78d26
commit 3df89dce43

@ -0,0 +1,4 @@
socket:
address: 0.0.0.0
port: 53

@ -1,6 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os, subprocess, socket, datetime, getopt, sys, re, atexit, logging as log import os, subprocess, socket, datetime, getopt, sys, re, atexit, yaml, logging as log
from pathlib import Path
import dns.flags import dns.flags
import dns.message import dns.message
@ -15,7 +16,9 @@ def main(args):
setupLogging(True) setupLogging(True)
log.debug("Logging started") log.debug("Logging started")
s = setupSocket('172.17.0.1', 53) config = readConfig("config.yml")
s = setupSocket(config['socket']['address'], config['socket']['port'])
startListen(s) startListen(s)
@ -25,7 +28,7 @@ def setupSocket(address, port):
return s return s
def startListen(s): def startListen(s):
log.debug('Now listening') log.debug(f'Now listening')
while True: while True:
(address, dmsg) = receiveFromWire(s) (address, dmsg) = receiveFromWire(s)
@ -98,5 +101,17 @@ def setupLogging(verbose: bool):
log.basicConfig(stream=sys.stdout, format=format, level=level) log.basicConfig(stream=sys.stdout, format=format, level=level)
def readConfig(file: str):
log.debug(f"Reading config '{file}'..")
if not os.path.isfile(file):
raise OSError(2, file)
return readYamlFile(file)
def readYamlFile(file: str):
with open(file, "r") as f:
return yaml.load(f, Loader=yaml.FullLoader)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

Loading…
Cancel
Save