Added support for secondary IP checks if primary fails (Fixes #111)

Updated requests module version
This commit is contained in:
Timothy Miller 2023-02-15 14:07:17 -05:00
parent 5c909e25cd
commit 2ad7e57d65
2 changed files with 37 additions and 13 deletions

View File

@ -66,9 +66,20 @@ def getIPs():
global shown_ipv4_warning
if not shown_ipv4_warning:
shown_ipv4_warning = True
print("🧩 IPv4 not detected")
if purgeUnknownRecords:
deleteEntries("A")
print("🧩 IPv4 not detected via 1.1.1.1, trying 1.0.0.1")
# Try secondary IP check
try:
a = requests.get(
"https://1.0.0.1/cdn-cgi/trace").text.split("\n")
a.pop()
a = dict(s.split("=") for s in a)["ip"]
except Exception:
global shown_ipv4_warning_secondary
if not shown_ipv4_warning_secondary:
shown_ipv4_warning_secondary = True
print("🧩 IPv4 not detected via 1.0.0.1. Verify your ISP or DNS provider isn't blocking Cloudflare's IPs.")
if purgeUnknownRecords:
deleteEntries("A")
if ipv6_enabled:
try:
aaaa = requests.get(
@ -79,16 +90,26 @@ def getIPs():
global shown_ipv6_warning
if not shown_ipv6_warning:
shown_ipv6_warning = True
print("🧩 IPv6 not detected")
if purgeUnknownRecords:
deleteEntries("AAAA")
print("🧩 IPv6 not detected via 1.1.1.1, trying 1.0.0.1")
try:
aaaa = requests.get(
"https://[2606:4700:4700::1001]/cdn-cgi/trace").text.split("\n")
aaaa.pop()
aaaa = dict(s.split("=") for s in aaaa)["ip"]
except Exception:
global shown_ipv6_warning_secondary
if not shown_ipv6_warning_secondary:
shown_ipv6_warning_secondary = True
print("🧩 IPv6 not detected via 1.0.0.1. Verify your ISP or DNS provider isn't blocking Cloudflare's IPs.")
if purgeUnknownRecords:
deleteEntries("AAAA")
ips = {}
if(a is not None):
if (a is not None):
ips["ipv4"] = {
"type": "A",
"ip": a
}
if(aaaa is not None):
if (aaaa is not None):
ips["ipv6"] = {
"type": "AAAA",
"ip": aaaa
@ -177,7 +198,7 @@ def cf_api(endpoint, method, config, headers={}, data=False):
"X-Auth-Key": config['authentication']['api_key']['api_key'],
}
try:
if(data == False):
if (data == False):
response = requests.request(
method, "https://api.cloudflare.com/client/v4/" + endpoint, headers=headers)
else:
@ -205,7 +226,9 @@ def updateIPs(ips):
if __name__ == '__main__':
shown_ipv4_warning = False
shown_ipv4_warning_secondary = False
shown_ipv6_warning = False
shown_ipv6_warning_secondary = False
ipv4_enabled = True
ipv6_enabled = True
purgeUnknownRecords = False
@ -244,13 +267,14 @@ if __name__ == '__main__':
if ttl < 30:
ttl = 30 #
print("⚙️ TTL is too low - defaulting to 30 seconds")
if(len(sys.argv) > 1):
if(sys.argv[1] == "--repeat"):
if (len(sys.argv) > 1):
if (sys.argv[1] == "--repeat"):
if ipv4_enabled and ipv6_enabled:
print(
"🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every " + str(ttl) + " seconds")
elif ipv4_enabled and not ipv6_enabled:
print("🕰️ Updating IPv4 (A) records every " + str(ttl) + " seconds")
print("🕰️ Updating IPv4 (A) records every " +
str(ttl) + " seconds")
elif ipv6_enabled and not ipv4_enabled:
print("🕰️ Updating IPv6 (AAAA) records every " +
str(ttl) + " seconds")

View File

@ -1 +1 @@
requests==2.28.1
requests==2.28.2