Advertisement
Guest User

check-host.net API

a guest
Jul 21st, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. import requests
  2. import json
  3. import sys
  4. import os
  5. import time
  6.  
  7. # Shortcut to clear terminal
  8. clear = ('cls' if os.name == 'nt' else 'clear')
  9.  
  10.  
  11. def check_host_data():
  12.     os.system(clear)
  13.     # Display availablemethods
  14.     methods = """
  15.    +------METHODS-------+
  16.    |  ping check: ping? |
  17.    |  HTTP check: http? |
  18.    |  TCP  check: tcp?  |
  19.    |  UDP  check: udp?  |
  20.    |  DNS  check: dns?  |
  21.    +--------------------+
  22.    """
  23.     print(methods)
  24.  
  25.     # List of methods available from API
  26.     method_list = ['ping', 'http', 'tcp', 'udp', 'dns']
  27.  
  28.     # Take input from user for target and method
  29.     target = input("[+] Enter your target: ")
  30.     method = input("[+] Enter your method: ").lower()
  31.  
  32.     # Check if method chosen by user is an available method
  33.     if method not in method_list:
  34.         print('\n[!] Invalid choice of method!\n    Please try again!')
  35.         time.sleep(1.5)
  36.         os.system(clear)
  37.         main()
  38.  
  39.     # API
  40.     api = 'https://check-host.net/check-{}?host={}&max_nodes=3'.format(target, method)
  41.     print("[*] Gathering info on {} via {}".format(target, method))
  42.  
  43.     # Scan results
  44.     try:
  45.         req = requests.get(api)
  46.         status = req.status_code
  47.         print('[*] HTTP status code: {}'.format(status))
  48.         if status != 404:
  49.             try:
  50.                 json_data = req.json()
  51.                 print(json_data)
  52.             except json.JSONDecodeError:
  53.                 print("\n[!] Error decoding JSON data\n    Please make sure the URL is correct")
  54.                 time.sleep(1.5)
  55.                 os.system(clear)
  56.                 main()
  57.         else:
  58.             print("\n[*] Host appears to be down right now\n    Please check your link to make sure")
  59.             time.sleep(1.5)
  60.             os.system(clear)
  61.     except Exception as e:
  62.             print("\n[!] {}".format(e))
  63.  
  64.  
  65. # Main loop
  66. def main():
  67.     # Ctrl + C will exit the loop
  68.     try:
  69.         check_host_data()
  70.     except KeyboardInterrupt:
  71.         sys.exit(0)
  72.     # Ask user if they want to scan another target; loop continues or breaks depending on input
  73.     prompt = input("\n[+] Would you like to scan another target [y/n]? ").lower()
  74.     done = False
  75.     while not done:
  76.         if prompt == 'y':
  77.             os.system(clear)
  78.             main()
  79.             done = True
  80.         elif prompt == 'n':
  81.             os.system(clear)
  82.             done = True
  83.         else:
  84.             print("\n[!] {} was an invalid choice. Please choose 'y' or 'n'.".format(prompt))
  85.             main()
  86.  
  87.  
  88. if __name__ == '__main__':
  89.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement