From b2821c58fc14f7bda4c202a8066d6688e5db360b Mon Sep 17 00:00:00 2001 From: Nima Taheri Date: Tue, 30 Jan 2018 13:35:56 +0330 Subject: [PATCH] Update and make it compatible with python3.6 --- README.md | 4 ++-- https_dns_proxy/__init__.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fbded9a..827adf6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Py-DNS-over-HTTPS-Proxy Provides a simple Python based proxy for running DNS over HTTPS to Google's DNS over HTTPS service. -Recently I wrote a blog post which probably gives you just enough information to get this up and running on a Mac / Linux box... https://robertputt.co.uk/securing-dns-traffic-with-dns-over-https.html, please note this script only seems to play nice with Python2.7 not Python 3.x +Recently I wrote a blog post which probably gives you just enough information to get this up and running on a Mac / Linux box... https://robertputt.co.uk/securing-dns-traffic-with-dns-over-https.html, This script plays nice with both Python2.7 and Python 3.x Configuration can be easily done with virtualenv: @@ -9,7 +9,7 @@ Configuration can be easily done with virtualenv: virtualenv dns_proxy cd dns_proxy/ source bin/activate -pip install dnslib requests +pip install configparser dnslib requests git clone https://github.com/robputt796/Py-DNS-over-HTTPS-Proxy.git cat Py-DNS-over-HTTPS-Proxy/https_dns_proxy/config.ini python Py-DNS-over-HTTPS-Proxy/https_dns_proxy/__init__.py & diff --git a/https_dns_proxy/__init__.py b/https_dns_proxy/__init__.py index bf99318..04fbd55 100644 --- a/https_dns_proxy/__init__.py +++ b/https_dns_proxy/__init__.py @@ -5,7 +5,7 @@ import base64 import os import datetime -import ConfigParser +from configparser import ConfigParser import sys from dnslib.server import DNSServer from dnslib.server import BaseResolver @@ -14,10 +14,10 @@ from dnslib import QTYPE # read from config.ini -myconfig = ConfigParser.ConfigParser() +myconfig = ConfigParser() config_name = 'config.ini' config_path = os.path.join(sys.path[0], config_name) -myconfig.readfp(open(config_path)) +myconfig.read_file(open(config_path)) if len(sys.argv) == 2: ENVIRONMENT=str(sys.argv[1]) @@ -58,16 +58,16 @@ def new_HTTPAdapter_build_response(self, request, resp): class HTTPSResolver(BaseResolver): def resolve(self, request, handler): - hostname = '.'.join(request.q.qname.label) + hostname = str(request.q.qname) ltype = request.q.qtype headers = {"Host": "dns.google.com"} try: if CACHE[hostname]['dt'] > datetime.datetime.now() - datetime.timedelta(minutes=30): - print "Cache Hit: %s" % hostname + print("Cache Hit: %s" % hostname) answer = CACHE[hostname][ltype] else: - print "Cache Expired: %s" % hostname + print("Cache Expired: %s" % hostname) del CACHE[hostname] raise Exception("Cache Expired") except: @@ -78,7 +78,7 @@ def resolve(self, request, handler): verify=False) if PINNED_CERT != lookup_resp.peercert: - print lookup_resp.peercert + print(lookup_resp.peercert) if EXIT_ON_MITM: print ("ERROR: REMOTE SSL CERT DID NOT MATCH EXPECTED (PINNED) " "SSL CERT, EXITING IN CASE OF MAN IN THE MIDDLE ATTACK") @@ -91,7 +91,7 @@ def resolve(self, request, handler): if lookup_resp.status_code == 200: try: - print "Cache Miss: %s" % hostname + print("Cache Miss: %s" % hostname) answer = json.loads(lookup_resp.text)['Answer'] CACHE[hostname] = {ltype: answer, "dt": datetime.datetime.now()} except: