Try
Dim siteUri As New System.Uri("http://www.microsoft.com")
Dim webRequest As System.Net.WebRequest = _
System.Net.WebRequest.Create(siteUri)
webRequest.Proxy = New System.Net.WebProxy("YourProxySetting")
Dim webResponse As System.Net.WebResponse = webRequest.GetResponse()
Catch ex As Exception
' The Web request failed.
End Try
How To Determine the Connection State of Your Local System and Initiate or End an Internet Connection by Using Microsoft Visual Basic .NET
http://support.microsoft.com/kb/821770/EN-US/
Link checker code:
http://www.codeproject.com/csharp/DavWebSpider.asp
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Int32, _
ByVal dwReserved As Int32) As Boolean
Private Enum Flags As Integer
'Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_INSTALLED = &H10
End Enum
'button1_click添加下面代码
Dim lngFlags As Long
If InternetGetConnectedState(lngFlags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_CONNECTION_LAN Then
'LAN connection.
MsgBox("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_MODEM Then
'Modem connection.
MsgBox("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_PROXY Then
'Proxy connection.
MsgBox("Proxy connection.")
End If
Else
'not connected.
MsgBox("Not connected.")
End If