summaryrefslogtreecommitdiff
path: root/domain
blob: 8ce1ccdfb1a32991f07c94a4214e6befcb901905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""
Check if domain is free or not. Requires `whois` and network.
"""
import argparse
import subprocess
import re

cli = argparse.ArgumentParser(description=__doc__)
cli.add_argument("hostname", help="the name to search, sans the .tld")
cli.add_argument(
    "-t",
    "--tlds",
    # this doesn't do anything because my registry database only has .com, .net,
    # and .edu
    help="list of tlds to search (default: 'com net')",
    nargs="+",
    default=["com", "net"],
)
cli.add_argument(
    "--abbrev",
    help="search hostname abbrevs, like 'internationalization' => 'i18n'",
    action="store_true",
)

args = cli.parse_args()


regex = r"^No match|^NOT FOUND|not found|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri"

for tld in args.tlds:
    domains = []
    domains.append(f"{args.hostname}.{tld}")
    if args.abbrev:
        a = args.hostname[0]
        b = str(len(args.hostname[1:-1]))
        c = args.hostname[-1]
        domains.append(f"{a}{b}{c}.{tld}")
    for domain in domains:
        res = subprocess.run(["whois", domain], stdout=subprocess.PIPE).stdout.decode(
            "utf-8"
        )
        if re.search(regex, res, re.IGNORECASE):
            print("ok:", domain)
        else:
            print("no:", domain)