No net connection

kurt69

Well-known member
Joined
Jan 17, 2006
Messages
78
Location
Australia
Programming Experience
Beginner
Hi simple question here, I'm using a web service (com.mcwtech.www) to retrieve a wide area network IP address, however I tested this on a system without an internet connection and the program freezes. How can I check for an internet connection?

This is what I'm hoping for:
VB.NET:
If netconnection.exists
Then retrieveIP.from.webservice
Else wanIPlabel.text = "some text"
End If
(This obviously isn't real code)
Thanks.
 
Just put a try catch around it

for example create a seperate function:

VB.NET:
 public function IsInternetConnected() as boolean
   try
      'do the request using webrequest, if it passes no exception will be thrown
      return true
   catch ex as exception
      return false
   end try
end function
 
Argh what am I doing wrong??????????
VB.NET:
    Public Function determineWAN_IPaddress() As Boolean
        Try
            Dim webRequest As Net.HttpWebRequest = webRequest.Create("http://www.google.com/index.html")
            Return True
        Catch ex As Exception
            lblWAN.Text = "Unable to determine WAN (Internet) Address."
            retrieveIP.Dispose()
            Return False
        Finally
            Dim ipService As New com.mcwtech.www.AddressInfo
            lblWAN.Text = "Internet Address: " & ipService.GetAddress
            retrieveIP.Dispose()
        End Try
    End Function

In debugging mode it gives me the exception dialogue box, help please.
 
Last edited:
Back
Top