mirror of
				https://github.com/KevinMidboe/cloudflare-ddns.git
				synced 2025-10-29 17:40:17 +00:00 
			
		
		
		
	Make sure that what we are comparing is acutal IP structure
This commit is contained in:
		
							
								
								
									
										10
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.py
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | |||||||
| import os | import os | ||||||
|  | import re | ||||||
| import requests | import requests | ||||||
| from bulk_dns_update import updateAllZones, setAPIKey, getDDNSAddresszoneId | from bulk_dns_update import updateAllZones, setAPIKey, getDDNSAddresszoneId | ||||||
| from notify import notify | from notify import notify | ||||||
| @@ -12,11 +13,18 @@ recordedIP = None | |||||||
| DDNS_ZONE = os.getenv('DDNS_ZONE') | DDNS_ZONE = os.getenv('DDNS_ZONE') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def validIP(ipString): | ||||||
|  |     ipRegex = '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' | ||||||
|  |     return re.search(ipRegex, ipString) | ||||||
|  |  | ||||||
| def publicAddress(): | def publicAddress(): | ||||||
|     global currentIP |     global currentIP | ||||||
|     logger.info('Getting public IP from ifconfg.me...') |     logger.info('Getting public IP from ifconfg.me...') | ||||||
|  |  | ||||||
|     r = requests.get('https://ifconfig.me') |     r = requests.get('https://ifconfig.me') | ||||||
|  |     if r.status_code != 200 or not validIP(r.text): | ||||||
|  |         return | ||||||
|  |  | ||||||
|     currentIP = r.text |     currentIP = r.text | ||||||
|     logger.info('Public IP: {}'.format(currentIP)) |     logger.info('Public IP: {}'.format(currentIP)) | ||||||
|  |  | ||||||
| @@ -28,7 +36,7 @@ def cloudflareDDNS(): | |||||||
|     recordedIP = ddnsRecord['content'] |     recordedIP = ddnsRecord['content'] | ||||||
|     logger.info('Found ddns recorded IP: {}'.format(recordedIP)) |     logger.info('Found ddns recorded IP: {}'.format(recordedIP)) | ||||||
|  |  | ||||||
|     if currentIP != recordedIP: |     if currentIP != recordedIP and validIP(recordedIP): | ||||||
|         logger.info('Public IP has changed, updating all A records.') |         logger.info('Public IP has changed, updating all A records.') | ||||||
|         return True |         return True | ||||||
|     else: |     else: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user