I get this error when trying to make a HTTP GET on https://bot.whatismyipaddress.com/ My code:
public void dostuff(){
...
targeturl = "https://bot.whatismyipaddress.com/";
response = _makeSimpleHttpRequest(targeturl, "GET", "");
...
}
public static String _makeSimpleHttpRequest(String targetUrl, String methodGetPostX, String postBody) throws MalformedURLException, IOException, NotImplementedException{
String responseline = "";
String temp = "";
HttpURLConnection httpConn = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
BufferedWriter bufferedWriter = null;
try {
java.net.URL url = null;
url = new java.net.URL(targetUrl); // system default DNS resolver
httpConn = (HttpURLConnection)url.openConnection(); // HERE THE ERROR OCCURED
...
}
The error:
W/System.err: java.net.UnknownHostException: Unable to resolve host "bot.whatismyipaddress.com": No address associated with hostname
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at com.android.okhttp.Dns$1.lookup(Dns.java:41)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:248)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30)
at mypackage.utils.CommonUtils._makeSimpleHttpRequest(CommonUtils.java:251)
at mypackage.utils.CommonUtils._makeSimpleHttpRequest(CommonUtils.java:293)
at mypackage.utils.CommonUtils.lambda$isNetworkAvailable$0(CommonUtils.java:77)
at mypackage.utils.-$$Lambda$CommonUtils$I9O8EFeqOM7bNsVQ5uILro0gOxg.call(Unknown Source:4)
at com.google.android.gms.tasks.zzy.run(com.google.android.gms:play-services-tasks@@17.2.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:929)
Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Linux.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
... 24 more
I changed DNS resolver to a self implemented DNS resolver. On the android device bot.whatismyipaddress.com can not be resolved. However whatismyipaddress.com is resolved correctly to a ipv4 address. With windows commandline i get the same result:
nslookup whatismyipaddress.com
Server: fritz.box
Address: 192.168.178.1
Nicht autorisierende Antwort:
Name: whatismyipaddress.com
Addresses: 2606:4700::6810:9b24
2606:4700::6810:9a24
104.16.154.36
104.16.155.36
>>
>>
nslookup bot.whatismyipaddress.com
Server: fritz.box
Address: 192.168.178.1
Name: bot.whatismyipaddress.com
(----- no Addresses! ----)
>>
>>
Previously it worked in the browser (both on phone and on PC). However after a few tries the browser got blocked aswell. The browser went through while the android native and nslookups failed already.
I changed the URL to another cloudflare server checkip.dyndns.org
which resulted in the same result. The android native HTTP-GET calls failed during DNS lookup instantly. The browser failed after a while.
I changed to a non-cloudflare server ipinfo.io/ip
which went through correctly.
I guess cloudflare webserver doesn't like the native android DNS resolver (or nslookup)... Maybe some kind of DDOS protection? Does anyone have an idea how to make a simple HTTP-GET to a cloudflare webserver from android without beeing blocked? I already tried alternating SSL Unsafe and the ip of the topdomain. However i think the problem is already in the DNS-Resolver step before performing any http calls... Thank you for a hint!
Device Huawei P30 pro VOG-L29 Android 10.1.0 Build 10.1.0.161(c431e23r2p5), problem exists both on WIFI and on mobile Data
CodePudding user response:
I think you may be extrapolating too much that this is an issue with Cloudflare or being blocked. A quick search of your first service results in a notice that they have shut it down (probably due to high usage) -
As of November 10, 2021 we are no longer providing this API due to massive abuse.
https://whatismyipaddress.com/api
Your other services could be experiencing similar issues with reliability. Server security wouldn't really cause DNS lookup to fail. Luckily there are many, many, alternatives you can try. For example -
Or Cloudflare even has an (undocumented) endpoint that could be used -
https://www.cloudflare.com/cdn-cgi/trace
At the end of the day though, if you want something reliable / guaranteed, you'll probably have to pay for it. Otherwise be prepared to shift to a new service every so often. Luckily the data returned should be easy to integrate (an IP address).