🧩 Disable IPv4 or IPv6 in config.json

This commit is contained in:
Timothy Miller 2021-03-16 20:53:28 -04:00
parent 6fe23a2aee
commit bdf8c75cad
3 changed files with 47 additions and 22 deletions

View File

@ -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",
```
### 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
```json

View File

@ -4,6 +4,8 @@ PATH = os.getcwd() + "/"
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
shown_ipv4_warning = False
shown_ipv6_warning = False
ipv4_enabled = True
ipv6_enabled = True
if(version < 3.5):
raise Exception("🐍 This script requires Python 3.5+")
@ -42,10 +44,9 @@ def deleteEntries(type):
print("🗑️ Deleted stale record " + identifier)
def getIPs():
global shown_ipv4_warning
global shown_ipv6_warning
a = None
aaaa = None
if ipv6_enabled:
try:
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
a.pop()
@ -55,6 +56,7 @@ def getIPs():
shown_ipv4_warning = True
print("🧩 IPv4 not detected")
deleteEntries("A")
if ipv4_enabled:
try:
aaaa = requests.get("https://[2606:4700:4700::1111]/cdn-cgi/trace").text.split("\n")
aaaa.pop()
@ -164,10 +166,22 @@ def updateIPs(ips):
commitRecord(ip)
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(sys.argv[1] == "--repeat"):
delay = 60
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()
killer = GracefulExit()
prev_ips = None

View File

@ -15,5 +15,7 @@
],
"proxied": false
}
]
],
"a": true,
"aaaa": true
}