Skip to content

Instantly share code, notes, and snippets.

@wmantly
Last active April 17, 2023 15:27
Show Gist options
  • Save wmantly/26ed89e34f2a0af562cf107db2b2136d to your computer and use it in GitHub Desktop.
Save wmantly/26ed89e34f2a0af562cf107db2b2136d to your computer and use it in GitHub Desktop.
import requests
import json
def get_ip():
res = requests.get('https://wtfismyip.com/json')
return res.json()['YourFuckingIPAddress']
class Godaddy:
def __init__(self, **kwargs):
self.__token_key = kwargs['token_key']
self.__token_secret = kwargs['token_secret']
self.base_url = kwargs.get('base_url', 'https://api.godaddy.com/v1/')
def __build_headers(self):
return {
'accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'sso-key {key}:{secret}'.format(
key= self.__token_key,
secret= self.__token_secret
)
}
def put(self, path, body=None):
body = body or ''
res = requests.put(
self.base_url+path,
headers=self.__build_headers(),
data=body
)
return res
def update_record(self, **kwargs):
domain = kwargs['domain']
data = kwargs['data']
name = kwargs.get('name', '@')
type = kwargs.get('type', 'A')
ttl = kwargs.get('ttl', 3600)
port = 1
weight = 1
path = 'domains/{domain}/records/{type}/{name}'.format(
domain=domain,
type=type,
name=name
)
body = [{
"data": data,
"port": port,
"priority": 0,
"protocol": "string",
"service": "string",
"ttl": 3600,
"weight": weight
}]
return self.put(path, json.dumps(body))
if __name__ == '__main__':
# Write some logic to load API keys, domaind and host from config file
public_ip = get_ip()
dns = Godaddy(token_key='' , token_secret='')
dns.update_record(domain='718it.biz', data=public_ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment