import requests import sys import json import datetime # Provide your keys apikey = "your_api_key" apisecret = "your_secret_key" # apiurl = "https://api.codepunch.com/dns/v2/" # get_api_token # token = get_api_token() # def get_api_token(): AUTHURLFMT = "{}auth/{}/{}" url = AUTHURLFMT.format(apiurl, apikey, apisecret) response = requests.get(url) if response.status_code == 200: apiresponse = response.json() else: raise Exception('Authentication: {}' . format(response.status_code)) if bool(apiresponse['status']) != True: raise Exception(apiresponse['error']) return apiresponse['token'] # get_api_data # parameters = {"kw": "wordpress"} # thedata = get_api_data(token, "nameservers", parameters) # print(thedata) # def get_api_data(token, command, parameters): APIURLFMT = "{}{}/{}/" url = APIURLFMT.format(apiurl, token, command) print(url) response = requests.get(url, params=parameters) if(response.status_code != 200): raise Exception('Invalid response code: {}' . format(response.status_code)) apiresponse = response.json() if bool(apiresponse['status']) != True: raise Exception(apiresponse['error']) return apiresponse ######################################################################################### # Get the token and then the data try: token = get_api_token() print("Token: " + token) # Find domains that contain wordpress keywords = "wordpress" parameters = {"kw": keywords} thedata = get_api_data(token, "nameservers", parameters) print (thedata) except Exception as e: print(repr(e));