I googled and googled, but this request is too close to "autodetect proxy setting" that is not the same thing - i'm just detecting if i need to query the user for the proxy setting.
I fixed most of it, by finding a way to detect networks in java, now it will not ask for proxy setting in a offline computer. It will still request them uselessly if google is down though, and that is sad... I don't want to test more sites, that just seems a waste of time. Do you know how to test for the principal DNS servers? Those should be fast.
Your idea of the http response seems very fine, but i didn't find a way to analyze the packets at such a level in pure java i think-
Relevant part of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| private void probeForProxy() { try{ Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); boolean upAndNotLocal = false; while (e.hasMoreElements()){ NetworkInterface n = e.nextElement(); if(!n.isLoopback() && n.isUp()){ upAndNotLocal = true; break; } } if (upAndNotLocal && tryDirectFailBecauseOfProxy("http://www.google.com")) { showRequestDialog(); } }catch(IOException e){ } } |
BTW really strange that a coding site hasn't the code tag as a button.