Link to home
Start Free TrialLog in
Avatar of fmichail
fmichailFlag for Canada

asked on

How to check the existence of a URL using vb.net which should detects its existence even if it is blocked

I am trying to make my win forms application checks the existence of a URL to check the registration information. I need to say if the site is down (i.e. the URL is not available) then consider that as a GO, otherwise check your registration and GO or NOT.

The question is is there a way to fool the code and make it believe falsely that the URL does not exist so that the registration validation will be skipped, Like using the firewalls ...etc?. Here is the code (I got it from the internet)



Function UrlExists(destination As String) As Boolean

    Dim url As New Uri(destination)
    Dim request As WebRequest = WebRequest.Create(url)

    Try
        Using response As WebResponse = request.GetResponse
            Return True
        End Using
    Catch ex As Exception
        Return False
    End Try

End Function
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Function UrlExists(destination As String) As Boolean
return false   ' pretend the URl doesn't exist
    Dim url As New Uri(destination)
    Dim request As WebRequest = WebRequest.Create(url)

    Try
        Using response As WebResponse = request.GetResponse
            Return True
        End Using
    Catch ex As Exception
        Return False
    End Try

End Function
You might want to consider some sort of flag for testing purposes.  eg.  (air code, might need some adjustment to compile)

Function UrlExists(destination As String, optional bTest as boolean = false) As Boolean
if bTest then return false    'if the boolean is true then pretend the URL is not existing
    Dim url As New Uri(destination)
    Dim request As WebRequest = WebRequest.Create(url)

    Try
        Using response As WebResponse = request.GetResponse
            Return True
        End Using
    Catch ex As Exception
        Return False
    End Try

End Function
Avatar of fmichail

ASKER

Hi Andy,
I am sorry, I think I mis-stated my question... The code that I provided is what I am doing, and the application will work in the following logical steps in any of my clients PC(s)

Go to the URL
Check the registration
if registration expired
     exit the application
else
    continue working
end if

Now the problem is if my URL does not exists temporarily for any reason, based on the previous logic, my clients application will fail. This is the problem that I need to fix by enhancing the logic using by adding the BOLD part as follows:

If URL exists

       Go to the URL
       Check the registration
       if registration expired
             exit the application
       else
           continue working
       end if
else
      Continue working this time
end if


Now it is my question, If I am a non-honest client (None of my clients are this way so far), and I want to fool the application by always making it feels that this URL does not exists and accordingly avoid the validation, can I do something like firewall, or any other trick to indicate falsely that the URL does not exist?
Yes.  Unplug the network cable - no internet - no verification.

Protecting your software from unlawful usage is not easy.  There are third party things for doing that.

If you want something simple then you might want to keep track of how many fails in a row and disable it if over that limit.  Or if it 'fails' at startup then keep trying every minute whilst the app is running.  Possibly disable some functionality is you can't check for verification (like a trial version functionality).....
Andy,
You are right, I think I need to have a third party "thing" do you recommend one, that is simple?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Andy
Thanks Andy