From 1006f5ed2974a943056933065dc7fbc713380bdf Mon Sep 17 00:00:00 2001 From: Jeffrey Dileo Date: Thu, 24 Jul 2014 04:03:55 -0400 Subject: [PATCH 1/3] help typo fix --- dnsRedir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsRedir.py b/dnsRedir.py index 1b8fc98..3a5a939 100755 --- a/dnsRedir.py +++ b/dnsRedir.py @@ -422,7 +422,7 @@ def parseNames(args) : return tab def getopts() : - p = optparse.OptionParser(usage="usage: %prog [opts] [type:name:val ...]") + p = optparse.OptionParser(usage="usage: %prog [opts] [type:name=val ...]") p.add_option('-d', dest='dnsServer', default=None, help='default DNS server. Default=' + publicDNS) p.add_option('-b', dest='bindAddr', default='', help='Address to bind to. Default=any') p.add_option('-p', dest='port', type=int, default=53, help='Port to listen on. Default=53') From 6d241cc218ca868a1352c6c535b9f6a52a228b86 Mon Sep 17 00:00:00 2001 From: Jeffrey Dileo Date: Thu, 24 Jul 2014 04:04:56 -0400 Subject: [PATCH 2/3] add ability to use config file --- dnsRedir.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dnsRedir.py b/dnsRedir.py index 3a5a939..8a88579 100755 --- a/dnsRedir.py +++ b/dnsRedir.py @@ -421,9 +421,21 @@ def parseNames(args) : tab.append((ty,pat,val)) return tab +def parseConfig(fileName) : + fd = open(fileName, "r") + config = fd.readlines(); fd.close() + args = [] + for line in config : + name = line.strip(' \t\r\n') + if name == '': + continue + args.append(name) + return parseNames(args) + def getopts() : p = optparse.OptionParser(usage="usage: %prog [opts] [type:name=val ...]") p.add_option('-d', dest='dnsServer', default=None, help='default DNS server. Default=' + publicDNS) + p.add_option('-c', dest='configFile', default=None, help='DNS configuration file. If set, command line type:name=val triplets will be ignored.') p.add_option('-b', dest='bindAddr', default='', help='Address to bind to. Default=any') p.add_option('-p', dest='port', type=int, default=53, help='Port to listen on. Default=53') p.add_option('-P', dest='dnsServerPort', type=int, default=53, help='Port of default DNS server. Default=53') @@ -431,7 +443,10 @@ def getopts() : p.add_option('-q', dest='quiet', action='store_true', help='Quiet') p.add_option('-6', dest='six', action='store_true', help='Use IPv6 server socket') opt,args = p.parse_args() - opt.names = parseNames(args) + if opt.configFile == None : + opt.names = parseNames(args) + else: + opt.names = parseConfig(opt.configFile) if opt.dnsServer == None : opt.dnsServer = publicDNS6 if opt.six else publicDNS opt.srv = opt.dnsServer, opt.dnsServerPort From 98153aca77878b3e258b5edc024407142e999dc0 Mon Sep 17 00:00:00 2001 From: Jeffrey Dileo Date: Thu, 24 Jul 2014 04:05:20 -0400 Subject: [PATCH 3/3] example config file --- example.conf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 example.conf diff --git a/example.conf b/example.conf new file mode 100644 index 0000000..97a1879 --- /dev/null +++ b/example.conf @@ -0,0 +1,3 @@ +A:www.evil.com.=1.2.3.4 +A:images.search.com.=0.1.2.3 +