|
-
Apr 29th, 2002, 05:39 AM
#1
Thread Starter
Addicted Member
How to check for net connection?
Whats the quickest and easiest way to check for a Internet Connection? I want it to return True or False, that simple.
Of course, I dont mean LAN, but Internet. If its a private IP (like 169.x.x.x) then I want it to be FALSE as well. You get the picture
VB6, VB.NET, C#, SQL, XML, ADO.NET, ASP.NET, HTML.
MCP & A+ Certified. Looking for a job in the Seattle, WA area.
-
Apr 29th, 2002, 06:24 AM
#2
Lively Member
It's that easy. Check out my site for this and many more in various languages:
http://users.chariot.net.au/~akia/Home.htm
Const RAS_MAXENTRYNAME = 256
Const RAS_MAXDEVICETYPE = 16
Const RAS_MAXDEVICENAME = 128
Const RAS_RASCONNSIZE = 412
Private Type RasConn
dwSize As Long
hRasConn As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
szDeviceType(RAS_MAXDEVICETYPE) As Byte
szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type
Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Private Sub CheckConnect()
Dim cnt As Long, lpRasConn(255) As RasConn, lpcb As Long
Dim lpcConnections As Long, hRasConn As Long
'Set the structure's size to the size of RAS_RASCONNSIZE
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
lpcConnections = 0
'Must call RasEnumConnections to recieve handle for RasHangUp
returncode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
If returncode = 0 Then
'YOU ARE CONNECTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
End If
End Sub
API, API, API: http://www.geocities.com/yaarwhooo/api.htm
-
Apr 29th, 2002, 06:28 AM
#3
VB Code:
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpSFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Command1_Click()
'posted by peet
If InternetGetConnectedState(0, 0) Then
MsgBox "Online"
Else
MsgBox "Offline"
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|