cloudflare-ddns
cloudflare-ddns copied to clipboard
The public IP is not correct
Describe the bug
Hi there, I have issue while running cloudflare-ddns.py without modification. The IP it sends to cloudflare is not the one I saw from the WAN of my router. The issue comes from the request https://1.1.1.1/cdn-cgi/trace, and after searching on the internet, I found a alternative public IP source https://ipinfo.io/ip, the one from it is exactly the public IP of my router. I'm not sure whether it's a bug or just for my use case.
Here's my modification:
def getIPs():
a = None
aaaa = None
global ipv4_enabled
global ipv6_enabled
global purgeUnknownRecords
if ipv4_enabled:
try:
a = requests.get("https://ipinfo.io/ip")
a = a.text.strip()
To Reproduce Steps to reproduce the behavior:
- Go to the router, check the public IP of WAN
- run
curl https://1.1.1.1/cdn-cgi/traceand check the IP from the response - run
curl https://ipinfo.io/ipand compare the IP from the step above
Expected behavior Both public IPs should be the same.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Ubuntu 20.04 LTS
Additional context
- Proxmox 8.0.3
- RouterOS 7.12
In my case, I run my nas behind a clash. The 1.1.1.1 hit clash's proxy rule, so that the public ip deteted was the proxy's ip.
I discovered the root cause of my issue: my internet provider does not offer a static public IP, resulting in the IP changing depending on the website used to check it. However, by utilizing RouterOS on my main router, I can access the actual public IP through its API. Here is the code I modified:
def getIPs():
a = None
aaaa = None
global ipv4_enabled
global ipv6_enabled
global purgeUnknownRecords
if ipv4_enabled:
try:
url = "{{your_router_ip}}"
auth = ("{{admin_username}}", "{{admin_password}}")
response = requests.get(url, auth=auth)
data = response.json()
a = "192.168.1.1"
for item in data:
ip = item["address"].split("/")[0]
if not ip.startswith("{{your_internal_ip_domain}}") and not ip.startswith("192"):
a = ip
break
...
If you encounter this issue, you can try solving it in a similar way on your own.