mirror of
https://github.com/KevinMidboe/cloudflare-ddns.git
synced 2025-10-29 17:40:17 +00:00
Send SMS to notify when IP cycles
This commit is contained in:
12
main.py
12
main.py
@@ -1,12 +1,14 @@
|
||||
import os
|
||||
import requests
|
||||
from bulk_dns_update import updateAllZones, setAPIKey, getDDNSAddresszoneId
|
||||
from notify import notify
|
||||
from dotenv import load_dotenv
|
||||
from logger import logger
|
||||
|
||||
load_dotenv()
|
||||
|
||||
currentIP = None
|
||||
recordedIP = None
|
||||
DDNS_ZONE = os.getenv('DDNS_ZONE')
|
||||
|
||||
|
||||
@@ -20,6 +22,7 @@ def publicAddress():
|
||||
|
||||
|
||||
def cloudflareDDNS():
|
||||
global recordedIP
|
||||
logger.info('Checking IP recorded in Cloudflare...')
|
||||
ddnsRecord = getDDNSAddresszoneId(DDNS_ZONE)
|
||||
recordedIP = ddnsRecord['content']
|
||||
@@ -27,9 +30,10 @@ def cloudflareDDNS():
|
||||
|
||||
if currentIP != recordedIP:
|
||||
logger.info('Public IP has changed, updating all A records.')
|
||||
updateAllZones(recordedIP, currentIP)
|
||||
return True
|
||||
else:
|
||||
logger.info('is same, exiting')
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
@@ -42,7 +46,11 @@ def main():
|
||||
setAPIKey(apiKey)
|
||||
|
||||
publicAddress()
|
||||
cloudflareDDNS()
|
||||
changed = cloudflareDDNS()
|
||||
|
||||
if changed:
|
||||
notify("IP changed to: {}. Updating all cloudflare zones!".format(currentIP))
|
||||
updateAllZones(recordedIP, currentIP)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user