Skip to content

Instantly share code, notes, and snippets.

@oscarvalenzuelab
Forked from mosajjal/dnschatserver.py
Created April 24, 2023 09:36
Show Gist options
  • Save oscarvalenzuelab/b6e67bdb1be3378beb5381ef54f24b30 to your computer and use it in GitHub Desktop.
Save oscarvalenzuelab/b6e67bdb1be3378beb5381ef54f24b30 to your computer and use it in GitHub Desktop.
DNS Chat server
import socket
from dnslib import RR, QTYPE, DNSRecord, DNSHeader, TXT
from time import time
DOMAIN = "REPLACE_WITH_YOUR_SUBDOMAIN"
def parse_response(data):
temp = DNSRecord.parse(data)
req = str(temp.q.qname)
subdomain = req.replace(DOMAIN, "")
return subdomain
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", 53))
print("starting the service..")
while True:
data, addr = sock.recvfrom(1024)
rec = parse_response(data)
epoch, msg = rec.split ("-|-")
print("[{}]: {}".format(epoch, msg))
msg = input("your reply: ")
nonce = str(int(time())) + "-|-"
temp = RR(DOMAIN, QTYPE.TXT, rdata=TXT(nonce + msg + DOMAIN))
rec = DNSRecord()
rec.add_question(DNSRecord.parse(data).q)
rec.add_answer(temp)
data = rec.pack()
sock.sendto(data, addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment