intruders

few scripts that checks two letter domains with .mk tld
Log | Files | Refs | README

commit 92ab661384069c8a6d22ba52117ea5dc2d094ac8
parent f980206aba4c78ad6841e6ba220ba981b0fe2abd
Author: tin <ichtinnotl@gmail.com>
Date:   Sun, 30 Dec 2018 14:59:41 +0100

renames few functions and vars

Diffstat:
intruders.py | 59+++++++++++++++++++++++++++++------------------------------
1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/intruders.py b/intruders.py @@ -2,13 +2,13 @@ import subprocess, itertools, time, sqlite3 import requests from bs4 import BeautifulSoup as bs -addresses = {'MK': 0, 'RS': 0, 'BG': 0, 'GR': 0, 'AL': 0, +country_codes = {'MK': 0, 'RS': 0, 'BG': 0, 'GR': 0, 'AL': 0, 'US': 0, 'CA': 0, 'DE': 0, 'FR': 0, 'ES': 0, 'SE': 0, 'RU': 0, 'IN': 0, 'CN': 0, 'JP': 0, 'MY': 0, 'GB': 0, 'OTHER_COUNTRY_CODES': 0, 'UNREGISTERED_DOMAINS': 0, 'TOTAL_FOREIGN_DOMAINS': 0} -alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', +letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] @@ -44,12 +44,12 @@ def fetch_domain_names(conn): cur = conn.cursor() cur.execute('SELECT domain_name FROM full_log WHERE address="CN"') - listOfDomains = [] + list_of_domains = [] for domain in cur.fetchall(): - listOfDomains.append(domain) + list_of_domains.append(domain) - return listOfDomains + return list_of_domains def ping_domains(domains, conn): cur = conn.cursor() @@ -75,7 +75,7 @@ def ping_domains(domains, conn): return None -def retreive_domain_data(domain): +def fetch_domain_data(domain): command = f"whois {domain} | grep 'domain:\|registered:\|expire:\|address:'" try : @@ -92,13 +92,13 @@ def beautify_output(output): domain_name = line.partition(':')[2].strip() if line.startswith("address:"): - address_name = line.partition(':')[2].strip() + country_code = line.partition(':')[2].strip() - if address_name in addresses: - addresses[address_name] += 1 + if country_code in country_codes: + country_codes[country_code] += 1 break - elif len(address_name) == 2 and address_name.isupper(): - addresses["OTHER_COUNTRY_CODES"] += 1 + elif len(country_code) == 2 and country_code.isupper(): + country_codes["OTHER_COUNTRY_CODES"] += 1 break else: pass @@ -109,11 +109,11 @@ def beautify_output(output): if line.startswith("expire:"): expire_date = line.partition(':')[2].strip() - return domain_name, address_name, register_date, expire_date + return domain_name, country_code, register_date, expire_date -def write_full_data_to_db(domain_name, address_name, register_date, expire_date, conn): +def write_full_data_to_db(domain_name, country_code, register_date, expire_date, conn): cur = conn.cursor() - query = f"INSERT INTO full_log VALUES ('{domain_name}', '{address_name}', '{register_date}', '{expire_date}')" + query = f"INSERT INTO full_log VALUES ('{domain_name}', '{country_code}', '{register_date}', '{expire_date}')" global database_saves try: @@ -132,17 +132,17 @@ def write_clean_data_to_db(conn): total_foreign_domains = 0 skip_address = ["MK", "UNREGISTERED_DOMAINS"] - for address in addresses: + for address in country_codes: if address in skip_address: pass else: - total_foreign_domains += addresses[address] + total_foreign_domains += country_codes[address] - addresses['TOTAL_FOREIGN_DOMAINS'] = total_foreign_domains + country_codes['TOTAL_FOREIGN_DOMAINS'] = total_foreign_domains - for address in addresses: + for address in country_codes: try: - query = f"INSERT INTO clean_log VALUES ('{address}', '{addresses[address]}')" + query = f"INSERT INTO clean_log VALUES ('{address}', '{country_codes[address]}')" cur.execute(query) print("The clean log was successfully written in the database") except Exception as e: @@ -154,7 +154,7 @@ def log_unregistered_domain(domain, conn): cur = conn.cursor() global database_saves - addresses["UNREGISTERED_DOMAINS"] += 1 + country_codes["UNREGISTERED_DOMAINS"] += 1 query = f"INSERT INTO unregistered_domains_log VALUES ('{domain}')" cur.execute(query) @@ -164,37 +164,36 @@ def log_unregistered_domain(domain, conn): return None -def combine_retreive_write(conn): +def combine_fetch_write(conn): cur = conn.cursor() - for (x, y) in itertools.product(alphabet, repeat = 2): + for (x, y) in itertools.product(letters, repeat = 2): domain = x + y + ".mk" - output = retreive_domain_data(domain) # get data for the domain + output = fetch_domain_data(domain) # get data for the domain if output: - domain_name, address_name, register_date, expire_date = beautify_output(output) - write_full_data_to_db(domain_name, address_name, register_date, expire_date, conn) + domain_name, country_code, register_date, expire_date = beautify_output(output) + write_full_data_to_db(domain_name, country_code, register_date, expire_date, conn) else: log_unregistered_domain(domain, conn) + write_clean_data_to_db(conn) + return None def main(): database = "mk_domains.db" - conn = create_connection(database) with conn: create_tables(conn) - combine_retreive_write(conn) + combine_fetch_write(conn) domain_names = fetch_domain_names(conn) ping_domains(domain_names, conn) - write_clean_data_to_db(conn) - - print("done...go on") + print("All good. Go on.") return None