GithubHelp home page GithubHelp logo

Comments (7)

vterron avatar vterron commented on August 17, 2024

Thanks for reaching out!

That's weird — https://api.ipify.org/ does work for me:

❯ curl https://api.ipify.org/ 
XXX.YYY.200.43

from public-ip.

h-bin-kim avatar h-bin-kim commented on August 17, 2024

I still can't reach it, so I don't know if there are any access restrictions due to country or specific conditions.

> curl https://api.ipify.org/ 
curl: (6) Could not resolve host: api.ipify.org

Glad most users have no issues.

from public-ip.

vterron avatar vterron commented on August 17, 2024

Interesting. Are you by any chance located in any of these countries?

2024-07-15-164630_663x595_scrot

They were failing last evening on https://www.whatsmydns.net/#A/api.ipify.org (error "DNS query timed out").

from public-ip.

h-bin-kim avatar h-bin-kim commented on August 17, 2024

Thank you for checking.
I am in South Korea. It is one of the countries where DNS lookups for api.ipify.org are not working.
I'm glad to know the cause!

from public-ip.

vterron avatar vterron commented on August 17, 2024

Thanks for confirming!

This is an interesting corner case — one of the backends not being reachable by a subset of users, for... whatever reason.

We could add some functionality to work around this (e.g. by adding a knob to exclude some of the servers), but would it be worth it? The default timeout is one second, and it can be modified when calling the get() function. Is this enough for you, or would you need to be able to exclude that server?

from public-ip.

h-bin-kim avatar h-bin-kim commented on August 17, 2024

First, there is an item to add for exception handling:

requests.exceptions.ConnectionError

The error I encountered was ConnectionError. By handling this exception, we can prevent unnecessary Traceback output.


However, exception handling will not improve response latency in my case.
Since this is an issue where no connection is established, setting a timeout doesn't help solve the problem.

0.024s elapsed for https://icanhazip.com
0.223s elapsed for https://checkip.amazonaws.com
0.241s elapsed for https://ipinfo.io/ip
0.282s elapsed for https://ipecho.net/plain
0.563s elapsed for https://ifconfig.co/ip
20.021s elapsed for https://api.ipify.org

from public-ip.

h-bin-kim avatar h-bin-kim commented on August 17, 2024

The simplest solution I found is to replace the URL https://api.ipify.org with https://api64.ipify.org. Fortunately, it appears that 'https://api64.ipify.org' is accessible from all countries.

'https://www.whatsmydns.net/#A/api64.ipify.org' (After a few attempts, it works fine in all countries.)

image

I considered various other solutions, but none were better than this I think.


Below are some of the alternative solutions I considered. This ties into a problem-solving pattern I often think about, and I don't dislike how such simple solutions(above) emerge after contemplation. :)

  1. Forcibly terminating the _get_ip thread based on timeout:

    • Since the time elapses in the requests.get() method's subroutine, it's not possible to forcibly terminate it properly from the thread.
    • While switching to the multiprocessing.Process method could achieve the desired outcome, I wanted to avoid using multiprocessing for this lightweight tool, so I kept this as a last resort.
  2. Simply removing https://api.ipify.org from the list:

    • Although not critical, I didn't want to solve the problem in such an irresponsible manner.
  3. Filtering URLs based on connectivity:

    • In my implementation, the connectivity check also took about 20 seconds regardless of the timeout setting. (for api.ipify.org)
    • Checking connectivity too quickly might be inaccurate.
  4. Checking the country setting in the OS and excluding api.ipify.org from the list only if it is KR:

    • No comments. 😂

from public-ip.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.