2023-01-07 14:52:19 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
import os
|
2023-01-07 15:28:37 +00:00
|
|
|
import re
|
2023-01-11 06:48:11 +00:00
|
|
|
import orjson
|
2023-01-07 14:52:19 +00:00
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="providence is an open source to find company domain names based on a given company name",
|
|
|
|
epilog="More info: https://github.com/adulau/providence",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument("-v", help="increase output verbosity", action="store_true")
|
2023-01-12 06:27:17 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-n", "--name", type=str, help="Company name to find", action="append"
|
|
|
|
)
|
2023-01-07 14:52:19 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-t",
|
|
|
|
"--tld",
|
|
|
|
type=str,
|
|
|
|
help="Limit to a specific TLD (if not, all known TLDs are tested)",
|
2023-01-12 06:27:17 +00:00
|
|
|
action="append",
|
2023-01-07 14:52:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
homedir = str(Path.home())
|
|
|
|
|
|
|
|
if not args.name:
|
|
|
|
parser.print_usage()
|
|
|
|
parser.exit()
|
|
|
|
|
|
|
|
|
|
|
|
def cache_suffixes(url="https://publicsuffix.org/list/public_suffix_list.dat"):
|
|
|
|
tlds = set()
|
|
|
|
cachedfile = os.path.join(homedir, ".providence-suffix")
|
|
|
|
if not os.path.exists(cachedfile):
|
|
|
|
r = requests.get(url)
|
|
|
|
with open(cachedfile, 'wb') as fd:
|
|
|
|
fd.write(r.content)
|
|
|
|
|
|
|
|
with open(cachedfile, 'r') as fd:
|
|
|
|
for line in fd:
|
|
|
|
tld = line.rstrip()
|
|
|
|
if not tld.startswith("//"):
|
|
|
|
tlds.add(tld)
|
|
|
|
return tlds
|
|
|
|
|
|
|
|
|
|
|
|
def guess_name(name=None, tlds=None):
|
2023-01-07 15:28:37 +00:00
|
|
|
guessed_names = set()
|
2023-01-07 14:52:19 +00:00
|
|
|
if name is None:
|
|
|
|
return False
|
|
|
|
for t in tlds:
|
2023-01-07 15:28:37 +00:00
|
|
|
guessed_names.add(f"{name}.{t}")
|
|
|
|
return guessed_names
|
2023-01-07 14:52:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if not args.tld:
|
|
|
|
tlds = cache_suffixes()
|
|
|
|
else:
|
2023-01-12 06:21:41 +00:00
|
|
|
tlds = args.tld
|
2023-01-07 14:52:19 +00:00
|
|
|
|
2023-01-07 15:28:37 +00:00
|
|
|
results = set()
|
|
|
|
|
2023-01-12 06:27:17 +00:00
|
|
|
|
|
|
|
def permutation_name(name_arg=None):
|
|
|
|
if name_arg is None:
|
|
|
|
return False
|
|
|
|
if re.search(r' {1,}', name_arg):
|
|
|
|
# replace with -
|
|
|
|
name = name_arg
|
|
|
|
reversed_name = " ".join(name_arg.split(" ")[::-1])
|
|
|
|
p = name.replace(" ", "-")
|
|
|
|
results.update(guess_name(name=p, tlds=tlds))
|
|
|
|
p = reversed_name.replace(" ", "-")
|
|
|
|
results.update(guess_name(name=p, tlds=tlds))
|
|
|
|
p = name.replace(" ", "")
|
|
|
|
results.update(guess_name(name=p, tlds=tlds))
|
|
|
|
p = reversed_name.replace(" ", "")
|
|
|
|
results.update(guess_name(name=p, tlds=tlds))
|
|
|
|
# try with removal of word
|
|
|
|
for word in name_arg.split(" "):
|
|
|
|
results.update(guess_name(name=word, tlds=tlds))
|
|
|
|
else:
|
|
|
|
results.update(guess_name(name=name_arg, tlds=tlds))
|
|
|
|
|
|
|
|
|
|
|
|
for name in args.name:
|
|
|
|
permutation_name(name_arg=name)
|
2023-01-07 15:28:37 +00:00
|
|
|
|
2023-01-11 06:48:11 +00:00
|
|
|
output = {}
|
|
|
|
output['results'] = list(results)
|
|
|
|
j = orjson.dumps(output).decode()
|
|
|
|
|
|
|
|
print(j)
|