-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsbllookup.py
38 lines (33 loc) · 1.11 KB
/
dnsbllookup.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
from flask import Flask
from flask import render_template
from flask import request
from flask import redirect
from flask import url_for
import dns.resolver
dnsbllookup = Flask(__name__)
@dnsbllookup.route('/')
def form():
return render_template('form_submit.html')
@dnsbllookup.route('/lookup/', methods=['POST'])
def lookup():
# Let us reverse this address for the DNSBL lookup
ip = request.form['ip']
reversedaddress = reverse(ip)
compiledquery = reversedaddress + ".dnsbl.ircops.org"
try:
dns.resolver.query(compiledquery, 'A')
ipstatus = True
reason = dns.resolver.query(compiledquery, 'TXT')
for rdata in reason:
reasonoutput = str(rdata)
except dns.resolver.NXDOMAIN:
ipstatus = False
if ipstatus is True:
output = ip + " is on the ircops DNSBL. " + "Reason: " + reasonoutput
else:
output = ip + " is not on the ircops DNSBL."
return render_template('form_action.html', output=output, ip=ip)
def reverse(ip):
splitlist = ip.split('.')[::-1]
reversedaddress = '.'.join(splitlist)
return reversedaddress