Not quoting anything because I'm just making a general reply, to the general problem that you're generally trying to solve. Generally.
You really should be using DNS for what you're trying to do, one way or the other. Reverse DNS, when set up properly, will always return the appropriate IP address for you. If this isn't achievable (I might scoff at a few dollars a year for a domain but others might not), then you should still be using DNS as a protocol, for both speed and reliability reasons. OpenDNS provides this a free service. dig +short myip.opendns.com @resolver1.opendns.com If you still don't want to use DNS for whatever reason, there are services that are designed for infrastructural reliability for this, namely: icanhazip.com [1] Since 2021 icanhazip is hosted by Cloudflare, and regardless of how you feel about CF as a company, the service is designed for speed and reliabilty for this exact purpose. 1: https://major.io/p/a-new-future-for-icanhazip/