massrdap- A high-performance RDAP resolver for bulk lookups and reconnaissance |
git clone git://git.acid.vegas/massrdap.git |
Log | Files | Refs | Archive | README | LICENSE |
whodap.py (2464B)
1 #!/usr/bin/env python 2 # RDAPr - developed by acidvegas (https://git.acid.vegas/massrdap) 3 4 import json 5 import urllib.request 6 import socket 7 import re 8 9 whois_rdap = {} 10 11 def whois_query(tld: str): 12 ''' 13 Queries the IANA WHOIS server for TLD information. 14 15 :param tld: The top-level domain to query. 16 ''' 17 18 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: 19 sock.connect(('whois.iana.org', 43)) 20 sock.sendall((f'{tld}\r\n').encode()) 21 response = b'' 22 while True: 23 data = sock.recv(4096) 24 if not data: 25 break 26 response += data 27 28 return response.decode(errors='replace') 29 30 31 def get_rdap(): 32 '''Fetches RDAP servers from IANA's RDAP Bootstrap file.''' 33 34 with urllib.request.urlopen('https://data.iana.org/rdap/dns.json') as response: 35 data = json.loads(response.read().decode('utf-8')) 36 37 for entry in data['services']: 38 tlds = entry[0] 39 rdap_url = entry[1][0] 40 41 for tld in tlds: 42 whois_rdap[tld] = {'rdap': rdap_url} 43 44 45 def get_whois(): 46 '''Fetches WHOIS servers from IANA's TLD list.''' 47 48 with urllib.request.urlopen('https://data.iana.org/TLD/tlds-alpha-by-domain.txt') as response: 49 tlds = response.read().decode('utf-8').lower().split('\n')[1:-1] 50 51 for tld in tlds: 52 if tld not in whois_rdap: 53 whois_rdap[tld] = {'rdap': None} 54 55 whois_data = whois_query(tld) 56 whois_server = None 57 for line in whois_data.split('\n'): 58 if 'whois:' in line: 59 parts = line.split() 60 if len(parts) > 1: 61 whois_server = parts[1] 62 break 63 64 if whois_server: 65 whois_rdap[tld]['whois'] = whois_server 66 print(f'WHOIS server for {tld}: {whois_server}') 67 else: 68 whois_rdap[tld]['whois'] = None 69 print(f'No WHOIS server for {tld}.') 70 71 72 73 if __name__ == '__main__': 74 get_rdap() 75 76 TOTAL = len(whois_rdap) 77 print(f'Found RDAP for {TOTAL:,} TLDs!') 78 79 get_whois() 80 print(f'RDAP is not available for {len(whois_rdap) - TOTAL:,} TLDs.') 81 82 whois_rdap = {key: whois_rdap[key] for key in sorted(whois_rdap)} 83 84 with open('rdaps.json', 'w') as file: 85 json.dump(whois_rdap, file, indent=4)