views:

660

answers:

3

Hi,

My app needs to make a GET request to a website and I'd like to be able to know if it's being blocked by a firewall, and ask the user to add an exception.

How can I find out that my get request failed because of a firewall, instead of something else?

+3  A: 

If it's a good firewall, you can't. Among other options, a firewall can:

  • reply with one of several different ICMP messages, indicating the destination is not accessible, or
  • silently discard the request, resulting in a timeout.

A reasonable option is to explain why the app was unable to access the website, and provide some helpful suggestions:

    No response from www.site.com:
    * Your computer may not be connected to the Internet.
    * The site may be down.
    * The site may be blocked by a firewall.
    The network indicated that www.site.com is not accessible:
    * Helpful messages go here.

The important point is to differentiate, perhaps better than I did above, between the types of failure, and the reasons behind them. For example, the steps for troubleshooting "no response" will be different from those for troubleshooting "the device told me it's not listening on that port."

Adam Liss
+1  A: 

Try to access the internet with a short timeout... If the command fails, you can suppose that the machine has a firewall which requires user interaction.

If the firewall is good, you can't detect it.

Martin K.
Access _what_ on the Internet? In general, the firewall is not on the user's machine; it's either on a corporate boundary or at the target's end -- firewalls (very generally) stop you from getting _into_, not _out of_, a particular machine.
Adam Liss
A: 

Use Win32 Firewall apis (classic)