-
-
Save oscarvalenzuelab/b6e67bdb1be3378beb5381ef54f24b30 to your computer and use it in GitHub Desktop.
DNS Chat server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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