Question

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?

Was it helpful?

Solution

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."

OTHER TIPS

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.

Use Win32 Firewall apis (classic)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top