Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Cuartin authored and Miguel Cuartin committed Feb 16, 2021
1 parent 14118e4 commit f8b542b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
47 changes: 47 additions & 0 deletions dnproxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import logging as l
import socket

from pyfiglet import Figlet

import dns.flags
import dns.message
import dns.rdataclass
import dns.rdatatype
import dns.name
import dns.query

from typing import cast

# General config
l.basicConfig(level=l.INFO)
f = Figlet(font='slant')

l.info(f.renderText('dnproxy'))

# General Parameters
HOST = '127.0.0.1'
PORT = 53
UPSTREAM_IP = '1.1.1.1'
TLS_HOSTNAME = 'cloudflare-dns.com'


with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
s.bind((HOST, PORT))
l.info(f"Listening on {HOST}:{PORT}")

while True:
(wire, host) = s.recvfrom(1024)
q = dns.message.from_wire(wire)
l.info(f'Question {q.id}:{q.question}')

try:
r = dns.query.tls(q, UPSTREAM_IP, server_hostname=TLS_HOSTNAME)
l.info(f'Response {r.id}:{r.answer}')

except KeyError:
l.error("error")

wire = r.to_wire()
s.sendto(wire, host)
Empty file added dnproxy.yml
Empty file.
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
cryptography==3.4.5
dnspython==2.1.0
idna==2.10
pycparser==2.20
pyfiglet==0.8.post1
requests==2.25.1
requests-toolbelt==0.9.1
urllib3==1.26.3

0 comments on commit f8b542b

Please sign in to comment.