intruders

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

commit ad662f930f976428f3d9b586d4425760e43a593f
parent 69075ecf2b0576e200d462256818e15145e16189
Author: tin <ichtinnotl@gmail.com>
Date:   Sun, 23 Dec 2018 01:40:21 +0100

adds script that pings domains and checks if they're alive

Diffstat:
alive.py | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 61 insertions(+), 18 deletions(-)

diff --git a/alive.py b/alive.py @@ -1,27 +1,70 @@ import requests, sqlite3 -from requests.exceptions import ConnectionError, TooManyRedirects +from bs4 import BeautifulSoup as bs -live = {} +def ping_domains(domains, conn): + cur = conn.cursor() + + for domain in domains: + domain = domain[0] + fullDomainName = "http://" + domain + + print(f"Sending a GET request to {domain}...") -def alive(): - conn = sqlite3.connect('two_letter_mk_domains_log.db') - c = conn.cursor() - - for row in c.execute('SELECT domainName FROM full_log WHERE address="CN"'): - domainName = row[0] - print("Checking ..." + row[0]) try: - request = requests.get("http://" + row[0]) - statusCode = request.status_code + request = requests.get(fullDomainName, timeout=3, allow_redirects=False) + status = request.status_code + title = str(bs(request.content, features="html.parser").title.string) + + query = f"INSERT INTO alive VALUES ('{domain}', '{status}', '{title}', 'YES')" + cur.execute(query) + except Exception as e: + query = f"INSERT INTO alive VALUES ('{domain}', '/', '/', 'NO')" + cur.execute(query) + + print(f"Domain {domain} is not responding: {e} ") + + return None + +def create_connection(db_file): + try: + conn = sqlite3.connect(db_file) + return conn + except Error as e: + print(e) + + return None + +def create_table(conn): + cur = conn.cursor() + + try: + cur.execute('''CREATE TABLE alive (domainName text, status text, title text, alive text)''') + except Exception: + print(e) + + return None + +def fetch_domain_names(conn): + cur = conn.cursor() + cur.execute('SELECT domainName FROM full_log WHERE address="CN"') + + listOfDomains = [] + + for domain in cur.fetchall(): + listOfDomains.append(domain) + + return listOfDomains - live[domainName] = statusCode - print(live) +def main(): + database = "two_letter_mk_domains_log.db" - print("Domain name {} returned status code of {}".format(domainName, statusCode)) - except ConnectionError: - print("Domain {} doesn't respond".format(domainName)) + conn = create_connection(database) + + with conn: + create_table(conn) + domain_names = fetch_domain_names(conn) + ping_domains(domain_names, conn) - print(live) return None -alive() +main()