diff --git a/update.py b/update.py index 99e83aa..5af02da 100644 --- a/update.py +++ b/update.py @@ -7,7 +7,8 @@ import json import argparse import sys -CURRENT_VERSION = "1.0-imanolbarba" +CURRENT_VERSION = "1.1-imanolbarba" +USER_AGENT_STRING = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36" DEBUG = 0 API_URL="https://domains.google.com/nic/update" @@ -86,12 +87,13 @@ def parseResponse(body): def updateRecord(username, password, hostname, address, offline): msgLog("Updating {} to {}".format(hostname, ("current IP address" if address == None else address)),TYPE_INFO) - updateParams = {"hostname" : (None, hostname), "offline": (None, ("yes" if offline == True else "no"))} + headers = {'User-Agent': USER_AGENT_STRING, 'Content-Type': 'application/x-www-form-urlencoded'} + updateParams = {"hostname" : hostname, "offline": ("yes" if offline == True else "no")} if(address != None): - updateParams["myip"] = (None, address) - req = requests.Request('POST', API_URL, auth=(username,password), files=updateParams) + updateParams["myip"] = address + req = requests.Request('POST', API_URL, auth=(username,password), headers=headers, data=updateParams) prep = req.prepare() - msgLog('Request:\n\n{} {}\n{}\n\n{}'.format(prep.method, prep.url,'\n'.join('{}: {}'.format(k, v) for k, v in prep.headers.items()),prep.body.decode()), TYPE_DEBUG) + msgLog('Request:\n\n{} {}\n{}\n\n{}'.format(prep.method, prep.url,'\n'.join('{}: {}'.format(k, v) for k, v in prep.headers.items()),prep.body), TYPE_DEBUG) rep = requests.Session().send(prep) msgLog('Response:\n\n{} {}\n{}\n\n{}'.format(rep.status_code, http.client.responses[rep.status_code],'\n'.join('{}: {}'.format(k, v) for k, v in rep.headers.items()),rep.content.decode()), TYPE_DEBUG) if(rep.status_code != 200):