Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions porkbun-ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def getMyIP():
def deleteRecord():
for i in getRecords(rootDomain)["records"]:
if i["name"]==fqdn and (i["type"] == 'A' or i["type"] == 'ALIAS' or i["type"] == 'CNAME'):
print("Deleting existing " + i["type"] + " Record")
deleteRecord = json.loads(requests.post(apiConfig["endpoint"] + '/dns/delete/' + rootDomain + '/' + i["id"], data = json.dumps(apiConfig)).text)
if i["content"] != myIP: # Only delete the record if the current value does not equal the public or provided IP
print("Deleting existing " + i["type"] + " Record")
deleteRecord = json.loads(requests.post(apiConfig["endpoint"] + '/dns/delete/' + rootDomain + '/' + i["id"], data = json.dumps(apiConfig)).text)
else:
print("Record matches your IP, doing nothing.")
return "noDelete"

def createRecord():
createObj=apiConfig.copy()
Expand Down Expand Up @@ -46,8 +50,9 @@ def createRecord():
else:
myIP=getMyIP() #otherwise use the detected exterior IP address

deleteRecord()
print(createRecord()["status"])
deleteStatus = deleteRecord()
if deleteStatus != "noDelete":
print(createRecord()["status"])

else:
print("Porkbun Dynamic DNS client, Python Edition\n\nError: not enough arguments. Examples:\npython porkbun-ddns.py /path/to/config.json example.com\npython porkbun-ddns.py /path/to/config.json example.com www\npython porkbun-ddns.py /path/to/config.json example.com '*'\npython porkbun-ddns.py /path/to/config.json example.com -i 10.0.0.1\n")