Results 1 to 3 of 3

Thread: How to check for net connection?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    Seattle, WA USA
    Posts
    216

    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.

  2. #2
    Lively Member
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    83
    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpSFlags As Long, ByVal dwReserved As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4. 'posted by peet
    5. If InternetGetConnectedState(0, 0) Then
    6.     MsgBox "Online"
    7. Else
    8.     MsgBox "Offline"
    9. End If
    10. 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
  •  



Click Here to Expand Forum to Full Width