From 8ecf74155f90efd10ff18692d420df76a52bcd17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87algan=20Ayg=C3=BCn?= Date: Thu, 26 Nov 2020 23:17:48 +0300 Subject: [PATCH] Update DNS method DNS over HTTPS integrated, 3rd party website removed --- modules/DNS.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/DNS.py b/modules/DNS.py index d0b56ba..6a9a363 100644 --- a/modules/DNS.py +++ b/modules/DNS.py @@ -1,4 +1,3 @@ -from bs4 import BeautifulSoup import requests from prettytable import PrettyTable from insides.bcolors import bcolors @@ -6,14 +5,26 @@ from insides.bcolors import bcolors def DNS(mail,_verbose=None): if _verbose != None: try: - at = "@" - domain = (mail[mail.index(at) + len(at):]) - dnsurl = ("https://api.hackertarget.com/dnslookup/?q="+domain) - dnstable = PrettyTable([f"{bcolors.WARNING}DNS LOOKUP{bcolors.ENDC}"]) - response = requests.get(dnsurl) - html = response.content - soup=BeautifulSoup(html,"html.parser") - dnstable.add_row([soup]) + print(f"{bcolors.WARNING} -- DNS Records [ Cloudflare ]{bcolors.ENDC}") + domain = mail.split("@")[1] + dnstable = PrettyTable([f"{bcolors.WARNING}Record Type{bcolors.ENDC}","Answer"]) + recordTypes = ["NS", "A", "AAAA", "TXT", "MX"] + for recordType in recordTypes: + params = ( + ('name', domain), + ('type', recordType), + ('cd', 'false'), + ) + + r = requests.get('https://cloudflare-dns.com/dns-query', headers={ 'accept': 'application/dns-json' }, params=params).json().get("Answer") or [] + + if recordType == "NS" and r == []: + print(f"{bcolors.FAIL}NS can not found! [ DNS Lookup ]{bcolors.ENDC}") + return + + for record in r: + value = record.get('data') + dnstable.add_row([recordType, value]) print(dnstable) except: - print(f"{bcolors.FAIL}Service Error! [ DNS Lookup ]{bcolors.ENDC}") + print(f"{bcolors.FAIL}Cloudflare DoH error!{bcolors.ENDC}") \ No newline at end of file