SSL/TLS Certs v2
Example Codes for TLS/SSL Certificate Data 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/tlscerts/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 = {"date": "20200624", "format": "json", "limit": 50, "kw": "apple"}
# thedata = get_api_data(token, "added", parameters)
# domaindata = thedata['data']
# for d in domaindata['data']:
# print (d['domain'])
#
def get_api_data(token, command, parameters):
APIURLFMT = "{}{}/{}/"
url = APIURLFMT.format(apiurl, token, command)
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)
yesterday = datetime.date.today() - datetime.timedelta(days=1)
datecode = yesterday.strftime("%Y%m%d")
# Find certificates that contain 'amazon'
keywords = "amazon"
parameters = {"date": datecode, "limit": 50, "kw": keywords}
thedata = get_api_data(token, "certificates", parameters)
certdata = thedata['data']
print (certdata)
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/tlscerts/v2/auth/$apikey/$apisecret/";
$contents = file_get_contents($url);
if($contents !== false) {
$contents = json_decode($contents, true);
$token = $contents['token'];
//////////////////////////////////////////////////////////////////////////////
// Get data for yesterday
$datecode = date("Ymd", strtotime("-1 days"));
$url = "https://api.codepunch.com/tlscerts/v2/$token/certificates/?kw=amazon&date=$datecode";
$contents = file_get_contents($url);
echo("<pre>");
$certs = json_decode($contents, true);
print_r($certs);
}