Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to allow using a config file #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions dnsRedir.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,32 @@ 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 = 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')
p.add_option('-t', dest='ttl', type=int, default=30, help='TTL for responses. Default=30 seconds')
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
Expand Down
3 changes: 3 additions & 0 deletions example.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A:www.evil.com.=1.2.3.4
A:images.search.com.=0.1.2.3