Added support for secondary IP checks if primary fails (Fixes #111)
Updated requests module version
This commit is contained in:
parent
5c909e25cd
commit
2ad7e57d65
@ -66,9 +66,20 @@ def getIPs():
|
|||||||
global shown_ipv4_warning
|
global shown_ipv4_warning
|
||||||
if not shown_ipv4_warning:
|
if not shown_ipv4_warning:
|
||||||
shown_ipv4_warning = True
|
shown_ipv4_warning = True
|
||||||
print("🧩 IPv4 not detected")
|
print("🧩 IPv4 not detected via 1.1.1.1, trying 1.0.0.1")
|
||||||
if purgeUnknownRecords:
|
# Try secondary IP check
|
||||||
deleteEntries("A")
|
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:
|
if ipv6_enabled:
|
||||||
try:
|
try:
|
||||||
aaaa = requests.get(
|
aaaa = requests.get(
|
||||||
@ -79,16 +90,26 @@ def getIPs():
|
|||||||
global shown_ipv6_warning
|
global shown_ipv6_warning
|
||||||
if not shown_ipv6_warning:
|
if not shown_ipv6_warning:
|
||||||
shown_ipv6_warning = True
|
shown_ipv6_warning = True
|
||||||
print("🧩 IPv6 not detected")
|
print("🧩 IPv6 not detected via 1.1.1.1, trying 1.0.0.1")
|
||||||
if purgeUnknownRecords:
|
try:
|
||||||
deleteEntries("AAAA")
|
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 = {}
|
ips = {}
|
||||||
if(a is not None):
|
if (a is not None):
|
||||||
ips["ipv4"] = {
|
ips["ipv4"] = {
|
||||||
"type": "A",
|
"type": "A",
|
||||||
"ip": a
|
"ip": a
|
||||||
}
|
}
|
||||||
if(aaaa is not None):
|
if (aaaa is not None):
|
||||||
ips["ipv6"] = {
|
ips["ipv6"] = {
|
||||||
"type": "AAAA",
|
"type": "AAAA",
|
||||||
"ip": 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'],
|
"X-Auth-Key": config['authentication']['api_key']['api_key'],
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
if(data == False):
|
if (data == False):
|
||||||
response = requests.request(
|
response = requests.request(
|
||||||
method, "https://api.cloudflare.com/client/v4/" + endpoint, headers=headers)
|
method, "https://api.cloudflare.com/client/v4/" + endpoint, headers=headers)
|
||||||
else:
|
else:
|
||||||
@ -205,7 +226,9 @@ def updateIPs(ips):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
shown_ipv4_warning = False
|
shown_ipv4_warning = False
|
||||||
|
shown_ipv4_warning_secondary = False
|
||||||
shown_ipv6_warning = False
|
shown_ipv6_warning = False
|
||||||
|
shown_ipv6_warning_secondary = False
|
||||||
ipv4_enabled = True
|
ipv4_enabled = True
|
||||||
ipv6_enabled = True
|
ipv6_enabled = True
|
||||||
purgeUnknownRecords = False
|
purgeUnknownRecords = False
|
||||||
@ -244,13 +267,14 @@ if __name__ == '__main__':
|
|||||||
if ttl < 30:
|
if ttl < 30:
|
||||||
ttl = 30 #
|
ttl = 30 #
|
||||||
print("⚙️ TTL is too low - defaulting to 30 seconds")
|
print("⚙️ TTL is too low - defaulting to 30 seconds")
|
||||||
if(len(sys.argv) > 1):
|
if (len(sys.argv) > 1):
|
||||||
if(sys.argv[1] == "--repeat"):
|
if (sys.argv[1] == "--repeat"):
|
||||||
if ipv4_enabled and ipv6_enabled:
|
if ipv4_enabled and ipv6_enabled:
|
||||||
print(
|
print(
|
||||||
"🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every " + str(ttl) + " seconds")
|
"🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every " + str(ttl) + " seconds")
|
||||||
elif ipv4_enabled and not ipv6_enabled:
|
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:
|
elif ipv6_enabled and not ipv4_enabled:
|
||||||
print("🕰️ Updating IPv6 (AAAA) records every " +
|
print("🕰️ Updating IPv6 (AAAA) records every " +
|
||||||
str(ttl) + " seconds")
|
str(ttl) + " seconds")
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
requests==2.28.1
|
requests==2.28.2
|
||||||
Reference in New Issue
Block a user