How to check if URL is blocked by my firewall

Nemin

I am trying to check if the URL is accessible or not. I am using HttpURLConnection for it. This is now I am implementing it.

public static boolean isUrlAccessible(final String urlToValidate)
            throws WAGException {
        URL url = null;
        HttpURLConnection huc = null;
        int responseCode = -1;
        try {
            url = new URL(urlToValidate);
            huc = (HttpURLConnection) url.openConnection();
            huc.setRequestMethod("HEAD");
            huc.connect();
            responseCode = huc.getResponseCode();
        } catch (final UnknownHostException e) {
            e.printStackTrace();
            System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
            return false;
        } catch (final MalformedURLException e){
            e.printStackTrace();
            System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
            return false;
        } catch (ProtocolException e) {
            e.printStackTrace();
            System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
            return false;
        } finally {
            if (huc != null) {
                huc.disconnect();
            }
        }
        return responseCode == 200;
    }

When the Internet is down it throws an UnknownHostException, I wanted to know how do I check if a fire wall is blocking a URL and thats why I get an exception and not because that the URL is not accessible. Also, I am just checking for response code 200 to make sure that the URL is accessible. Are there any other checks I need to perform?

user207421

When the Internet is down it throws an UnknownHostException

No, it throws that when the DNS is down or the host isn't known to DNS.

I wanted to know how do I check if a fire wall is blocking a URL

You will get a connect timeout. In rare cases with obsolete hardware you may get a connection refusal, but I haven't heard of that this century. But you will also get a connect timeout if the host is down.

I am just checking for response code 200 to make sure that the URL is accessible. Are there any other checks I need to perform?

No. But URLs aren't blocked by firewalls. Ports are blocked by firewalls.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delphi check if port is not blocked by firewall

From Dev

how to check my youtube channel live or die[Blocked] with C#?

From Dev

Nmap scan on my LAN is blocked by my host firewall (Linux)

From Dev

How to check company firewall

From Dev

How to check if Task thread is blocked

From Dev

How to check if Task thread is blocked

From Dev

How to easily determine, which outbound ports aren't blocked by firewall

From Dev

How to re-trigger "Windows firewall has blocked..." message?

From Dev

How to check for blocked ports with VB.NET

From Dev

how to check if firewall is stopped on redhat 7

From Dev

Why are localhost connections blocked by the firewall?

From Dev

incoming traffic blocked in firewall logs

From Dev

Why are localhost connections blocked by the firewall?

From Dev

How my RAMs are blocked at 2666MHz?

From Dev

Symfony 2.8 - How to configure a firewall for any URL?

From Dev

Mystery firewall? Checklist for diagnosing blocked incoming connections

From Dev

Google Chrome being blocked by company firewall

From Dev

Outgoing network blocked (NOT firewall), incoming connections ok

From Dev

How to check with JavaScript if web server port is being blocked

From Dev

How do I check if a youtube video is blocked/restricted/deleted

From Dev

Check if website is in the blocked list

From Dev

I have blocked port 80 and 443 on Windows 10 via making a new Firewall rule but I still can browse. How to I block HTTP traffic via firewall?

From Dev

How to check my niceness?

From Dev

How to check my niceness?

From Dev

How do I find my firewall is blocking mysql?

From Dev

How can I configure my firewall to work with Docker?

From Dev

How do I find my firewall is blocking mysql?

From Dev

How can I configure my firewall to work with Docker?

From Dev

Why are my bindings blocked?

Related Related

  1. 1

    Delphi check if port is not blocked by firewall

  2. 2

    how to check my youtube channel live or die[Blocked] with C#?

  3. 3

    Nmap scan on my LAN is blocked by my host firewall (Linux)

  4. 4

    How to check company firewall

  5. 5

    How to check if Task thread is blocked

  6. 6

    How to check if Task thread is blocked

  7. 7

    How to easily determine, which outbound ports aren't blocked by firewall

  8. 8

    How to re-trigger "Windows firewall has blocked..." message?

  9. 9

    How to check for blocked ports with VB.NET

  10. 10

    how to check if firewall is stopped on redhat 7

  11. 11

    Why are localhost connections blocked by the firewall?

  12. 12

    incoming traffic blocked in firewall logs

  13. 13

    Why are localhost connections blocked by the firewall?

  14. 14

    How my RAMs are blocked at 2666MHz?

  15. 15

    Symfony 2.8 - How to configure a firewall for any URL?

  16. 16

    Mystery firewall? Checklist for diagnosing blocked incoming connections

  17. 17

    Google Chrome being blocked by company firewall

  18. 18

    Outgoing network blocked (NOT firewall), incoming connections ok

  19. 19

    How to check with JavaScript if web server port is being blocked

  20. 20

    How do I check if a youtube video is blocked/restricted/deleted

  21. 21

    Check if website is in the blocked list

  22. 22

    I have blocked port 80 and 443 on Windows 10 via making a new Firewall rule but I still can browse. How to I block HTTP traffic via firewall?

  23. 23

    How to check my niceness?

  24. 24

    How to check my niceness?

  25. 25

    How do I find my firewall is blocking mysql?

  26. 26

    How can I configure my firewall to work with Docker?

  27. 27

    How do I find my firewall is blocking mysql?

  28. 28

    How can I configure my firewall to work with Docker?

  29. 29

    Why are my bindings blocked?

HotTag

Archive