🧩 Disable IPv4 or IPv6 in config.json
This commit is contained in:
parent
6fe23a2aee
commit
bdf8c75cad
@ -59,6 +59,15 @@ Alternatively, you can use the traditional API keys by setting appropriate value
|
|||||||
"account_email": "The email address you use to sign in to cloudflare",
|
"account_email": "The email address you use to sign in to cloudflare",
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Enable or disable IPv4 or IPv6
|
||||||
|
|
||||||
|
Some ISP provided modems only allow port forwarding over IPv4 or IPv6. In this case, you would want to disable any interface not accessible via port forward.
|
||||||
|
|
||||||
|
```json
|
||||||
|
"a": true,
|
||||||
|
"aaaa": true
|
||||||
|
```
|
||||||
|
|
||||||
### Other values explained
|
### Other values explained
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|||||||
@ -4,6 +4,8 @@ PATH = os.getcwd() + "/"
|
|||||||
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
||||||
shown_ipv4_warning = False
|
shown_ipv4_warning = False
|
||||||
shown_ipv6_warning = False
|
shown_ipv6_warning = False
|
||||||
|
ipv4_enabled = True
|
||||||
|
ipv6_enabled = True
|
||||||
|
|
||||||
if(version < 3.5):
|
if(version < 3.5):
|
||||||
raise Exception("🐍 This script requires Python 3.5+")
|
raise Exception("🐍 This script requires Python 3.5+")
|
||||||
@ -42,28 +44,28 @@ def deleteEntries(type):
|
|||||||
print("🗑️ Deleted stale record " + identifier)
|
print("🗑️ Deleted stale record " + identifier)
|
||||||
|
|
||||||
def getIPs():
|
def getIPs():
|
||||||
global shown_ipv4_warning
|
|
||||||
global shown_ipv6_warning
|
|
||||||
a = None
|
a = None
|
||||||
aaaa = None
|
aaaa = None
|
||||||
try:
|
if ipv6_enabled:
|
||||||
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
|
try:
|
||||||
a.pop()
|
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
|
||||||
a = dict(s.split("=") for s in a)["ip"]
|
a.pop()
|
||||||
except Exception:
|
a = dict(s.split("=") for s in a)["ip"]
|
||||||
if not shown_ipv4_warning:
|
except Exception:
|
||||||
shown_ipv4_warning = True
|
if not shown_ipv4_warning:
|
||||||
print("🧩 IPv4 not detected")
|
shown_ipv4_warning = True
|
||||||
deleteEntries("A")
|
print("🧩 IPv4 not detected")
|
||||||
try:
|
deleteEntries("A")
|
||||||
aaaa = requests.get("https://[2606:4700:4700::1111]/cdn-cgi/trace").text.split("\n")
|
if ipv4_enabled:
|
||||||
aaaa.pop()
|
try:
|
||||||
aaaa = dict(s.split("=") for s in aaaa)["ip"]
|
aaaa = requests.get("https://[2606:4700:4700::1111]/cdn-cgi/trace").text.split("\n")
|
||||||
except Exception:
|
aaaa.pop()
|
||||||
if not shown_ipv6_warning:
|
aaaa = dict(s.split("=") for s in aaaa)["ip"]
|
||||||
shown_ipv6_warning = True
|
except Exception:
|
||||||
print("🧩 IPv6 not detected")
|
if not shown_ipv6_warning:
|
||||||
deleteEntries("AAAA")
|
shown_ipv6_warning = True
|
||||||
|
print("🧩 IPv6 not detected")
|
||||||
|
deleteEntries("AAAA")
|
||||||
ips = {}
|
ips = {}
|
||||||
if(a is not None):
|
if(a is not None):
|
||||||
ips["ipv4"] = {
|
ips["ipv4"] = {
|
||||||
@ -164,10 +166,22 @@ def updateIPs(ips):
|
|||||||
commitRecord(ip)
|
commitRecord(ip)
|
||||||
|
|
||||||
if __name__ == '__main__' and config is not None:
|
if __name__ == '__main__' and config is not None:
|
||||||
|
try:
|
||||||
|
ipv4_enabled = config["a"]
|
||||||
|
ipv6_enabled = config["aaaa"]
|
||||||
|
except:
|
||||||
|
ipv4_enabled = True
|
||||||
|
ipv6_enabled = True
|
||||||
|
print("⚙️ Individually disable IPv4 or IPv6 with new config.json options. Read more about it here: https://github.com/timothymiller/cloudflare-ddns/blob/master/README.md")
|
||||||
if(len(sys.argv) > 1):
|
if(len(sys.argv) > 1):
|
||||||
if(sys.argv[1] == "--repeat"):
|
if(sys.argv[1] == "--repeat"):
|
||||||
delay = 60
|
delay = 60
|
||||||
print("🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every minute")
|
if ipv4_enabled and ipv6_enabled:
|
||||||
|
print("🕰️ Updating IPv4 (A) & IPv6 (AAAA) records every minute")
|
||||||
|
elif ipv4_enabled and not ipv6_enabled:
|
||||||
|
print("🕰️ Updating IPv4 (A) records every minute")
|
||||||
|
elif ipv6_enabled and not ipv4_enabled:
|
||||||
|
print("🕰️ Updating IPv6 (AAAA) records every minute")
|
||||||
next_time = time.time()
|
next_time = time.time()
|
||||||
killer = GracefulExit()
|
killer = GracefulExit()
|
||||||
prev_ips = None
|
prev_ips = None
|
||||||
|
|||||||
@ -15,5 +15,7 @@
|
|||||||
],
|
],
|
||||||
"proxied": false
|
"proxied": false
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"a": true,
|
||||||
|
"aaaa": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user