Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The public IP is not correct #161

Closed
leoli-dev opened this issue Nov 22, 2023 · 2 comments
Closed

The public IP is not correct #161

leoli-dev opened this issue Nov 22, 2023 · 2 comments
Assignees

Comments

@leoli-dev
Copy link

leoli-dev commented Nov 22, 2023

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:

  1. Go to the router, check the public IP of WAN
  2. run curl https://1.1.1.1/cdn-cgi/trace and check the IP from the response
  3. run curl https://ipinfo.io/ip and 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
@EeeMt
Copy link

EeeMt commented May 4, 2024

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.

@leoli-dev
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants