Need a way to discover if i'm behind a proxy

To popup a dialog so users can configure it. I already have a popup and it works, but the method i use, (querying by http if google is reachable) besides being lame and slow, also can’t distinguish between no connection and a proxy firewall, so the dialog appears when it shouldn’t.

Any way to test this?

Did you google it? Sounds like a typical problem. Maybe a HTTP response contains some info in the header from a proxy, when one is active. I cannot look for more details myself right now, I have no more time. But this is what I would try, to find out if a proxy somehow gives a sign in its HTTP response.

-JAW

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.

you can try to open an URLConnection (HTTPConnection) to your website and check usingProxy() method

Actually this would only work, if the proxy is already configured, which is the problem the OP is facing.

@OP
I think your solution is as good as it gets. You could also try to search for ways how to get the proxy settings from the OS or from different browsers, but I think if the proxy ist correctly configured in the OS, java should also have the proxy set right straigt away.

hum… I guess that if the user reach its website, proxy setting maybe already set properly, no ?

[quote=“i30817,post:3,topic:34056”]
I imagine the principal DNS servers will reject packets on port 80, so they don’t help detect a proxy.