Example Codes for DNS Data Feed API (v2)
Python, Example Code
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));
PHP Example Code
List recently added domains that contain the words paypal or amazon.
<?php
$apikey = "paste_your_key_here";
$apisecret = "paste_your_secret_here";
// Authenticate and get token
$url = "https://api.codepunch.com/dns/v2/auth/$apikey/$apisecret/";
$contents = file_get_contents($url);
if($contents !== false) {
$contents = json_decode($contents, true);
$token = $contents['token'];
//////////////////////////////////////////////////////////////////////////////
// Get all nameservers that contain wordpress
$url = "https://api.codepunch.com/dns/v2/$token/nameservers/?kw=wordpress";
$contents = file_get_contents($url);
echo("<pre>");
$nsdata = json_decode($contents, true);
print_r($nsdata);
}