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:
/**
* Probe for a working network, and show a input dialog
* for proxy config if needed
*/
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){
//if getNetworkInterfaces() threw a exception there is
//NO network, and thus, no need to show the dialog.
//if there are, proxy for acess to http. If can't connnect
//then, show dialog.
}
}
BTW really strange that a coding site hasn’t the code tag as a button.