def get_domain_list(logger, n_sites, out_path): """Load the top million domains from disk or the web""" top_1m_file = os.path.join(out_path, MAJESTIC_URL.split('/')[-1]) pyfunc_cache_file = os.path.join(out_path, 'pyfunceable_cache.json') # download the file if it doesn't exist or if it's more than a week stale if (not os.path.exists(top_1m_file) or time.time() - os.path.getmtime(top_1m_file) > WEEK_IN_SECONDS): logger.info( 'Loading new Majestic data and refreshing PyFunceble cache') response = urlopen(MAJESTIC_URL) with open(top_1m_file, 'w') as f: f.write(response.read().decode()) # if the majestic file is expired, let's refresh the pyfunceable cache if os.path.exists(pyfunc_cache_file): os.remove(pyfunc_cache_file) # load cache if os.path.exists(pyfunc_cache_file): with open(pyfunc_cache_file) as f: pyfunc_cache = json.load(f) else: pyfunc_cache = {} domains = [] with open(top_1m_file) as f: # first line is CSV header next(f) # only read the first n_sites lines for l in f: domain = l.split(',')[2] if domain in pyfunc_cache: if pyfunc_cache[domain] == 'ACTIVE': domains.append(domain) else: status = PyFunceble(domain) logger.info('PyFunceble: %s is %s', domain, status) if status == 'ACTIVE': domains.append(domain) pyfunc_cache[domain] = status if len(domains) >= n_sites: break # save pyfunceble cache again with open(pyfunc_cache_file, 'w') as f: json.dump(pyfunc_cache, f) return domains
def domain_status(domain_or_ip): """ Check the status of the given domain name or IP. Argument: - domain_or_ip: str The domain or IPv4 to test. Returns: str The status of the domain. """ return PyFunceble(domain_or_ip)
""" This is a basic example which prints one of the official output of PyFunceble. Note: * Official output: ACTIVE, INACTIVE, INVALID """ from PyFunceble import test as PyFunceble from PyFunceble import url_test as PyFuncebleURL print("Start of basic example.") DOMAIN = "github.com" URL = "https://{}".format(DOMAIN) print(DOMAIN, PyFunceble(domain=DOMAIN)) print(URL, PyFuncebleURL(url=URL)) print("End of basic example ")
from PyFunceble import test as PyFunceble import urllib3 urllib3.disable_warnings() readfile = open("splitblock12", "r") DOMAINS = [] for line in readfile: line_list = line.strip() DOMAINS.append(line_list) readfile.close() def print_result(subject, status): if status != "ACTIVE": print(f"{domain} is {status}") file.writelines(f"{domain}\n") file = open('deadblock12', 'a') for domain in DOMAINS: print_result(domain, PyFunceble(domain)) file.close()
""" This is an advanced example which get more information about the tested element. """ from json import dumps from PyFunceble import test as PyFunceble from PyFunceble import url_test as PyFuncebleURL CONFIG = {"no_whois": True, "db_type": "json"} SUBJECTS = ["google.com", "github.com", "example.org", "8.8.8.8", "8.4.4.8"] for subject in SUBJECTS: output = PyFunceble(subject=subject, complete=True, config=CONFIG) url_output = PyFuncebleURL( subject="https://{}".format(subject), complete=True, config=CONFIG ) print("============== COMPLETE DATA: {0} ==============".format(output["tested"])) print(dumps(output, indent=4, ensure_ascii=False, sort_keys=True)) print( "=============================={0}===============".format( "=" * len(output["tested"]) ) ) print( "============== COMPLETE DATA: {0} ==============".format(url_output["tested"]) )
""" This is an advanced example which get more information about the tested element. """ from PyFunceble import test as PyFunceble from PyFunceble import url_test as PyFuncebleURL CONFIG = {"no_whois": True} DOMAIN = "google.com" DOMAIN_RESULT_FROM_API = PyFunceble(domain=DOMAIN, complete=True, config=CONFIG) URL_RESULT_FROM_API = PyFuncebleURL(url="https://{}".format(DOMAIN), complete=True, config=CONFIG) print("Start of information from API for {}.".format(DOMAIN)) print("nslookup", DOMAIN_RESULT_FROM_API["nslookup"]) print("domain_syntax_validation", DOMAIN_RESULT_FROM_API["domain_syntax_validation"]) print(DOMAIN_RESULT_FROM_API["tested"], DOMAIN_RESULT_FROM_API["status"]) print("nslookup", URL_RESULT_FROM_API["nslookup"]) print("domain_syntax_validation", URL_RESULT_FROM_API["domain_syntax_validation"]) print("url_syntax_validation", URL_RESULT_FROM_API["url_syntax_validation"]) print(URL_RESULT_FROM_API["tested"], DOMAIN_RESULT_FROM_API["status"]) print(f"End of information from API for {DOMAIN}.")
""" This is a basic example which prints one of the availability of the given domain and URL. .. note: Official output: ACTIVE, INACTIVE, INVALID """ from PyFunceble import load_config from PyFunceble import test as PyFunceble from PyFunceble import url_test as PyFuncebleURL load_config(custom={"db_type": "json"}) print("Start of basic example.") DOMAIN = "github.com" URL = "https://{}".format(DOMAIN) print(DOMAIN, PyFunceble(subject=DOMAIN)) print(URL, PyFuncebleURL(subject=URL)) print("End of basic example ")
""" This is an advanced example which prints some information about the tested element. Note: * Official output: ACTIVE, INACTIVE, INVALID """ from PyFunceble import test as PyFunceble from PyFunceble import url_test as PyFuncebleURL DOMAIN = "google.com" DOMAIN_RESULT_FROM_API = PyFunceble(domain=DOMAIN, complete=True) URL_RESULT_FROM_API = PyFuncebleURL(url="https://{}".format(DOMAIN), complete=True) print("Start of information from API for {}.".format(DOMAIN)) print("nslookup", DOMAIN_RESULT_FROM_API["nslookup"]) print("domain_syntax_validation", DOMAIN_RESULT_FROM_API["domain_syntax_validation"]) print(DOMAIN_RESULT_FROM_API["tested"], DOMAIN_RESULT_FROM_API["status"]) print("nslookup", URL_RESULT_FROM_API["nslookup"]) print("domain_syntax_validation", URL_RESULT_FROM_API["domain_syntax_validation"]) print("url_syntax_validation", URL_RESULT_FROM_API["url_syntax_validation"]) print(URL_RESULT_FROM_API["tested"], DOMAIN_RESULT_FROM_API["status"]) print("End of information from API for {DOMAIN}.")