1 | | - | from bs4 import BeautifulSoup |
2 | 1 | | import requests |
3 | 2 | | from prettytable import PrettyTable |
4 | 3 | | from insides.bcolors import bcolors |
| skipped 1 lines |
6 | 5 | | def DNS(mail,_verbose=None): |
7 | 6 | | if _verbose != None: |
8 | 7 | | try: |
9 | | - | at = "@" |
10 | | - | domain = (mail[mail.index(at) + len(at):]) |
11 | | - | dnsurl = ("https://api.hackertarget.com/dnslookup/?q="+domain) |
12 | | - | dnstable = PrettyTable([f"{bcolors.WARNING}DNS LOOKUP{bcolors.ENDC}"]) |
13 | | - | response = requests.get(dnsurl) |
14 | | - | html = response.content |
15 | | - | soup=BeautifulSoup(html,"html.parser") |
16 | | - | dnstable.add_row([soup]) |
| 8 | + | print(f"{bcolors.WARNING} -- DNS Records [ Cloudflare ]{bcolors.ENDC}") |
| 9 | + | domain = mail.split("@")[1] |
| 10 | + | dnstable = PrettyTable([f"{bcolors.WARNING}Record Type{bcolors.ENDC}","Answer"]) |
| 11 | + | recordTypes = ["NS", "A", "AAAA", "TXT", "MX"] |
| 12 | + | for recordType in recordTypes: |
| 13 | + | params = ( |
| 14 | + | ('name', domain), |
| 15 | + | ('type', recordType), |
| 16 | + | ('cd', 'false'), |
| 17 | + | ) |
| 18 | + | |
| 19 | + | r = requests.get('https://cloudflare-dns.com/dns-query', headers={ 'accept': 'application/dns-json' }, params=params).json().get("Answer") or [] |
| 20 | + | |
| 21 | + | if recordType == "NS" and r == []: |
| 22 | + | print(f"{bcolors.FAIL}NS can not found! [ DNS Lookup ]{bcolors.ENDC}") |
| 23 | + | return |
| 24 | + | |
| 25 | + | for record in r: |
| 26 | + | value = record.get('data') |
| 27 | + | dnstable.add_row([recordType, value]) |
17 | 28 | | print(dnstable) |
18 | 29 | | except: |
19 | | - | print(f"{bcolors.FAIL}Service Error! [ DNS Lookup ]{bcolors.ENDC}") |
20 | | - | |
| 30 | + | print(f"{bcolors.FAIL}Cloudflare DoH error!{bcolors.ENDC}") |