-
Notifications
You must be signed in to change notification settings - Fork 4
/
webdns.py
executable file
·79 lines (56 loc) · 1.59 KB
/
webdns.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
#!/usr/bin/env python
import argparse
import os
try:
from bottle import route, run, response
except ImportError:
raise ImportError("Please install bottle.py, exiting.")
try:
import dns.resolver
except ImportError:
raise ImportError("Please install dnspython, exiting")
# Globals
RESOLVER = dns.resolver.Resolver()
def set_nameservers(servers):
if isinstance(servers, list):
print "Using %s as nameservers." % str(servers)
RESOLVER.nameservers = servers
else:
raise TypeError("'server' must be a list")
@route('/favicon.ico')
def favicon():
return ''
@route('/')
@route('/<name>')
@route('/<record_type>/<name>')
def index(record_type='A', name='www.google.com'):
response.content_type = 'text/plain'
try:
results = str(RESOLVER.query(name, record_type).response)
except dns.resolver.NXDOMAIN:
results = 'NXDOMAIN'
except dns.resolver.NoAnswer:
results = 'NoAnswer'
except:
results = 'Unknown'
finally:
return results
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--nameserver',
default=[],
required=False,
action='append',
dest='nameservers',
help="Set various DNS servers to use by IP address")
parser.add_argument(
'--port',
default=8080,
type=int,
required=False,
help="Port to listen on")
args = parser.parse_args()
if args.nameservers:
set_nameservers(args.nameservers)
run(host='0.0.0.0', port=os.environ.get('PORT', args.port))