Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import sys
- import os
- import time
- # Shortcut to clear terminal
- clear = ('cls' if os.name == 'nt' else 'clear')
- def check_host_data():
- os.system(clear)
- # Display availablemethods
- methods = """
- +------METHODS-------+
- | ping check: ping? |
- | HTTP check: http? |
- | TCP check: tcp? |
- | UDP check: udp? |
- | DNS check: dns? |
- +--------------------+
- """
- print(methods)
- # List of methods available from API
- method_list = ['ping', 'http', 'tcp', 'udp', 'dns']
- # Take input from user for target and method
- target = input("[+] Enter your target: ")
- method = input("[+] Enter your method: ").lower()
- # Check if method chosen by user is an available method
- if method not in method_list:
- print('\n[!] Invalid choice of method!\n Please try again!')
- time.sleep(1.5)
- os.system(clear)
- main()
- # API
- api = 'https://check-host.net/check-{}?host={}&max_nodes=3'.format(target, method)
- print("[*] Gathering info on {} via {}".format(target, method))
- # Scan results
- try:
- req = requests.get(api)
- status = req.status_code
- print('[*] HTTP status code: {}'.format(status))
- if status != 404:
- try:
- json_data = req.json()
- print(json_data)
- except json.JSONDecodeError:
- print("\n[!] Error decoding JSON data\n Please make sure the URL is correct")
- time.sleep(1.5)
- os.system(clear)
- main()
- else:
- print("\n[*] Host appears to be down right now\n Please check your link to make sure")
- time.sleep(1.5)
- os.system(clear)
- except Exception as e:
- print("\n[!] {}".format(e))
- # Main loop
- def main():
- # Ctrl + C will exit the loop
- try:
- check_host_data()
- except KeyboardInterrupt:
- sys.exit(0)
- # Ask user if they want to scan another target; loop continues or breaks depending on input
- prompt = input("\n[+] Would you like to scan another target [y/n]? ").lower()
- done = False
- while not done:
- if prompt == 'y':
- os.system(clear)
- main()
- done = True
- elif prompt == 'n':
- os.system(clear)
- done = True
- else:
- print("\n[!] {} was an invalid choice. Please choose 'y' or 'n'.".format(prompt))
- main()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement