From 23f146fd80a4e692dd54a6222cfc0725c46fe108 Mon Sep 17 00:00:00 2001 From: vili Date: Sat, 8 Jul 2023 13:20:13 +0300 Subject: [PATCH] Some changes to different utils and update version string --- h4xtools.py | 3 +-- utils/ip_lookup.py | 1 + utils/port_scanner.py | 2 +- utils/web_scrape.py | 2 +- utils/websearch.py | 49 ++++++++++++++++++++++++++++++------------- utils/wifi_finder.py | 4 ++-- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/h4xtools.py b/h4xtools.py index eab044f..8726965 100755 --- a/h4xtools.py +++ b/h4xtools.py @@ -33,7 +33,7 @@ if os.name == "posix": os.system("clear") -version = "0.2.11" +version = "0.2.12" def internet_check(): @@ -333,7 +333,6 @@ def __main__(): print_banner() time.sleep(1) print_menu() - time.sleep(1) a = input("[*] Select your option : \t") if a in menu_options: diff --git a/utils/ip_lookup.py b/utils/ip_lookup.py index 6765ec2..97c2dc8 100644 --- a/utils/ip_lookup.py +++ b/utils/ip_lookup.py @@ -44,6 +44,7 @@ def __init__(self, ip): printer.success(f"Lat - ", values['lat']) printer.success(f"Lon - ", values['lon']) printer.success(f"AS - ", values['as']) + printer.success(f"Maps URL - ", f"https://www.google.com/maps/search/{values['lat']},{values['lon']}") except Exception as e: printer.error(f"Error : ", e) diff --git a/utils/port_scanner.py b/utils/port_scanner.py index 576331f..9cb92a7 100644 --- a/utils/port_scanner.py +++ b/utils/port_scanner.py @@ -41,7 +41,7 @@ def __init__(self, ip, port_range): else: printer.success(f"Found {len(open_ports)} open ports in '{ip}'..!") except KeyboardInterrupt: - printer.error("Keyboard Interrupt Detected..!") + printer.error("Cancelled..!") def scan(ip, port_range): diff --git a/utils/web_scrape.py b/utils/web_scrape.py index f1da835..b092582 100644 --- a/utils/web_scrape.py +++ b/utils/web_scrape.py @@ -39,7 +39,7 @@ def __init__(self, url): time.sleep(1) for link in soup.find_all("a"): count += 1 - printer.info(f"found {count} link(s) : ", link.get("href")) + printer.info(f"found {count} link(s) : ", link.get("href"), " - " + link.text) except Exception as e: printer.error(f"Error : ", e) pass diff --git a/utils/websearch.py b/utils/websearch.py index 573cec8..1984c6e 100644 --- a/utils/websearch.py +++ b/utils/websearch.py @@ -31,17 +31,38 @@ class Search: def __init__(self, query): url = "https://duckduckgo.com/html/?q=" + query headers = {"User-Agent": random.choice(users)} - r = requests.get(url, headers=headers) - soup = BeautifulSoup(r.text, "html.parser") - results = soup.find_all("div", {"class": "result__body"}) - - if len(results) == 0: - printer.error(f"Error : No results found for {query}..!") - return - - printer.info(f"Searching for '{query}' -- With the agent {headers['User-Agent']}") - time.sleep(1) - for result in results: - title = result.find("a", {"class": "result__a"}).text - link = result.find("a", {"class": "result__a"})["href"] - printer.success(f"{title} - {link}") + + try: + response = requests.get(url, headers=headers) + response.raise_for_status() # Raise exception if request fails + + soup = BeautifulSoup(response.text, "html.parser") + results = soup.find_all("div", {"class": "result__body"}) + + if len(results) == 0: + printer.error(f"No results found for '{query}'..!") + return + + printer.info(f"Searching for '{query}' -- With the agent '{headers['User-Agent']}'") + time.sleep(1) + for result in results: + print_result(result) + + except requests.exceptions.RequestException as e: + printer.error(f"Error : {e}") + pass + except KeyboardInterrupt: + printer.error("Cancelled..!") + pass + + +def print_result(result): + """ + Prints the result of a search. + + :param result: The result to print. + """ + title = result.find("a", {"class": "result__a"}).text + link = result.find("a", {"class": "result__a"})["href"] + status = requests.get(link).status_code + printer.success(f"'{title}' - {link} - [{status}]") diff --git a/utils/wifi_finder.py b/utils/wifi_finder.py index c7c4b5d..38758b5 100644 --- a/utils/wifi_finder.py +++ b/utils/wifi_finder.py @@ -34,11 +34,11 @@ def __init__(self): try: subprocess.run(["netsh", "wlan", "show", "networks"], check=True) except subprocess.CalledProcessError as e: - printer.error(f"Error: {e.returncode}") + printer.error(f"Error : {e.returncode}") else: printer.info("Linux system detected..! Doing an nmcli scan...") time.sleep(1) try: subprocess.run(["nmcli", "dev", "wifi"], check=True) except subprocess.CalledProcessError as e: - printer.error(f"Error: {e.returncode}") + printer.error(f"Error : {e.returncode}")