Commit aa88d0580308aff20ab25604097a9717b5a799b6

Authored by Imanol-Mikel Barba Sabariego
1 parent e21a568f

Changing request to urlencoded

Showing 1 changed file with 7 additions and 5 deletions
update.py
... ... @@ -7,7 +7,8 @@ import json
7 7 import argparse
8 8 import sys
9 9  
10   -CURRENT_VERSION = "1.0-imanolbarba"
  10 +CURRENT_VERSION = "1.1-imanolbarba"
  11 +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"
11 12 DEBUG = 0
12 13  
13 14 API_URL="https://domains.google.com/nic/update"
... ... @@ -86,12 +87,13 @@ def parseResponse(body):
86 87  
87 88 def updateRecord(username, password, hostname, address, offline):
88 89 msgLog("Updating {} to {}".format(hostname, ("current IP address" if address == None else address)),TYPE_INFO)
89   - updateParams = {"hostname" : (None, hostname), "offline": (None, ("yes" if offline == True else "no"))}
  90 + headers = {'User-Agent': USER_AGENT_STRING, 'Content-Type': 'application/x-www-form-urlencoded'}
  91 + updateParams = {"hostname" : hostname, "offline": ("yes" if offline == True else "no")}
90 92 if(address != None):
91   - updateParams["myip"] = (None, address)
92   - req = requests.Request('POST', API_URL, auth=(username,password), files=updateParams)
  93 + updateParams["myip"] = address
  94 + req = requests.Request('POST', API_URL, auth=(username,password), headers=headers, data=updateParams)
93 95 prep = req.prepare()
94   - 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)
  96 + 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)
95 97 rep = requests.Session().send(prep)
96 98 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)
97 99 if(rep.status_code != 200):
... ...