Skip to content

Instantly share code, notes, and snippets.

@devanshbatham
Created November 9, 2020 10:57
Show Gist options
  • Save devanshbatham/3f5c043e4bbbc2d3d2e23b74db310404 to your computer and use it in GitHub Desktop.
Save devanshbatham/3f5c043e4bbbc2d3d2e23b74db310404 to your computer and use it in GitHub Desktop.
sslExtract : Extract DNS records from IP addresses
#!/usr/bin/env python
from multiprocessing.pool import ThreadPool
from time import time as timer
from urllib.request import urlopen
import sys
import re
import os.path
start = timer()
def main():
all_domains = []
regex = r'of.*\'$'
urls = []
for line in sys.stdin:
urls.append(line.strip())
def fetch_url(url):
try:
response = urlopen(url, timeout=5)
return url, response.read(), None
except Exception as e:
return url, None, e
results = ThreadPool(25).imap_unordered(fetch_url, urls)
for url, html, error in results:
if error is None:
print("\u001b[31m[NONE] No DNS records found " + url + "\u001b[0m")
else:
if "of " in str(error):
print("\n\u001b[33m[INFO] Fetching DNS records from \u001b[36m"+url + "\u001b[0m")
domains = re.findall(regex, str(error))
temp = domains[0][3:].strip()
domains = temp.split(',')
domains[0] = ' ' + domains[0]
for i in domains:
print('\u001b[32m ' + i[2:-1] + "\u001b[0m")
all_domains.append(i[2:-1])
all_domains_unique = list(set(all_domains))
with open('all-domains.txt', 'a') as f:
for i in all_domains_unique:
f.write(f"{i}\n")
print("\n\u001b[31m-----------------------------------\n[INFO] IPs checked: " + str(len(urls)))
print("\u001b[31m[INFO] Domains found: " + str(len(all_domains_unique)))
if __name__ == "__main__":
if os.path.isfile('all-domains.txt'):
os.remove('all-domains.txt')
main()
print("\u001b[31m[INFO] Elapsed Time: %s\u001b[0m" % (timer() - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment