I am in China, ipv6 is being gradually promoted, it is unstable, sometimes it can be accessed, sometimes it is not. My Android app uses java language and requests ipv6 by default. Sometimes the ipv6 of the server is unavailable. I want to switch to ipv4 quickly. Therefore, I want to check whether the ipv6 of the server is accessible before making a network request. What should i do?
I'm not a Java guy, but I was able to come up with this.
Process ping_6_proc = runtime.exec("ping6 your::IPv6::goes::here%your_interface");
int exit_value = ping_6_proc.waitFor();
If exit_value
is 0, then you had a successful ping. Else, swap over to IPv4.