Page 1 of 1

InternetGetConnectedState_

Posted: Thu Aug 14, 2008 2:23 am
by Chirantha
Its returning 0 even when I'm connected to the internet :( why is this :(

Posted: Thu Aug 14, 2008 2:32 am
by Sparkie

Posted: Thu Aug 14, 2008 3:25 am
by Rook Zimbabwe
Karma

Posted: Thu Aug 14, 2008 10:56 am
by PB
> Karma

:lol:

Posted: Thu Aug 14, 2008 12:45 pm
by SFSxOI
The MS knowledgebase article only applies to Microsoft Windows Millennium Edition. Are you still using Millennium Edition (WinME) ?

Its possible for it to return a 0 all the time also if your behind a router sometimes.

Posted: Thu Aug 14, 2008 1:29 pm
by Sparkie
msdn wrote:This parameter may return a valid flag even when the function returns FALSE.
My question to you is what is returning 0, the function or the parameter?

Code: Select all

Debug InternetGetConnectedState_(@ics, 0)
Debug ics

Posted: Thu Aug 14, 2008 7:35 pm
by SFSxOI
The MSDN says this:
(http://msdn.microsoft.com/en-us/library ... S.85).aspx)

A return value of TRUE indicates that either the modem connection is active, or a LAN connection is active and a proxy is properly configured for the LAN. A return value of FALSE indicates that neither the modem nor the LAN is connected. If FALSE is returned, the INTERNET_CONNECTION_CONFIGURED flag may be set to indicate that autodial is configured to "always dial" but is not currently active. If autodial is not configured, the function returns FALSE.

Posted: Thu Aug 14, 2008 8:44 pm
by TerryHough
I've been using this for years. However, it happily reports the system "can connect" because it is configured to connect even when it physically cannot connect due to a disconnected LAN cable. So, you may need to expand it to ping an known good site to be sure.

Code: Select all

; HowIsInternet  -  09/22/2003 updated by TerryHough
; (c) ses007, 2003
; From PB forum, topic
; http://purebasic.myforums.net/viewtopic.php?t=5590

#INTERNET_CONNECTION_MODEM      = $1
#INTERNET_CONNECTION_LAN        = $2
#INTERNET_CONNECTION_PROXY      = $4
#INTERNET_CONNECTION_MODEM_BUSY = $8
#INTERNET_CONNECTION_OFFLINE    = $20
#INTERNET_CONNECTION_CONFIGURED = $40
#INTERNET_RAS_INSTALLED         = $10


Procedure.s InternetStatus()
  Protected dwflags.b
  Protected sFlags.s
  Protected msg.s
  If InternetGetConnectedState_(@dwflags, 0)
    sFlags.s = RSet(Bin(dwflags),8,"0")
    
    If Mid(sFlags,8,1) = "1"    ; = #INTERNET_CONNECTION_MODEM
      msg + "The Internet connection is made by a modem" + Chr(10)
    EndIf
    
    If Mid(sFlags,7,1) = "1"    ; = #INTERNET_CONNECTION_LAN
      msg + "The Internet connection is made via a network (LAN)"
    EndIf
    
    If Mid(sFlags,6,1) = "1" And Mid(sFlags,4,1) = "0"  ; = #INTERNET_CONNECTION_PROXY
      msg + " and using a Proxy server." + Chr(10)
    Else
      msg + "." + Chr(10)
    EndIf
    
    If Mid(sFlags,6,1) = "1" And Mid(sFlags,4,1) = "1"  ; = #INTERNET_CONNECTION_OFFLINE
      msg + "The Internet connection is currently offline. " + Chr(10)
    EndIf
    
    If Mid(sFlags,5,1) = "1" And Mid(sFlags,7,1) = "1"  ; = #INTERNET_RAS_INSTALLED
      msg + "A Remote Access Service (RAS) is installed." + Chr(10)
    EndIf
    
    If Mid(sFlags,5,1) = "1" And Mid(sFlags,6,1) = "0"  ; = #INTERNET_CONNECTION_MODEM_BUSY
      msg + "The modem is busy with another connection." + Chr(10)
    EndIf
    
    If Mid(sFlags,3,1) = "1" And Mid(sFlags,5,1) = "1"  ; = #INTERNET_CONNECTION_CONFIGURED
      msg + "An Internet connection is configured." + Chr(10)
    EndIf
    
    If Mid(sFlags,4,1) = "1" And Mid(sFlags,6,1) = "1"  ; = #INTERNET_CONNECTION_OFFLINE
      msg + "The Internet connection is currently offline. " + Chr(10)
    EndIf
    ;msg + "dwFlags: " + sFlags + Chr(10) + Chr(10)
    
  Else
    msg = "Currently, there is no Internet connection." + Chr(10) + Chr(10)
  EndIf
  
  ProcedureReturn msg
EndProcedure

msg.s = InternetStatus()

Result.l = InternetAttemptConnect_(0)
If Result = #ERROR_SUCCESS
  msg + "This system is currently connected or can connect to the Internet."
Else
  msg + "This system cannot connect to the Internet."
  errNumber.l = GetErrorNumber()
  errDescription.s = GetErrorDescription()
  msg + "Error Number: " + Str(errNumber) + Chr(10) + errDescription
EndIf
MessageRequester("Internet Connection", msg, #MB_ICONINFORMATION)

Posted: Thu Aug 14, 2008 9:03 pm
by rsts
add this to my other response from your previous post

if InternetCheckConnection_("http://yoursite.com",1 ,0)

cheers

Posted: Sat Aug 23, 2008 4:18 pm
by SFSxOI
Terry;

This part of your code:

Code: Select all

If Mid(sFlags,7,1) = "1"    ; = #INTERNET_CONNECTION_LAN 
      msg + "The Internet connection is made via a network (LAN)" 
    EndIf
Is sort of ambigious. If your connected to the internet via a cable modem, but not through a LAN (or network router/switch) it still reports the connection as made thru a network (LAN). Is there some other way to detect if the computer is not actually on a network and is connected straight through to the internet via another method?

(yes, I know a cable modem connection thru the ISP could be considered a network.)

Posted: Mon Aug 25, 2008 7:26 pm
by TerryHough
I can't really tell you.

If the cable modem connects to a Network Interface Card, the system would assume it was on a network simply because it could be.

If the cable modem connects via an USB port, the modem itself becomes the network interface. So, again the system thinks it is on a network.

That would be my simplistic explanation.

Posted: Mon Aug 25, 2008 7:45 pm
by SFSxOI
I wonder if there is some way to detect what is on the other side of a NIC? I tried detecting the cable modems internal html page (almost all cable modems have them), and it worked, so i thought for a bit that :

Code: Select all

if CableModemInternalWebpageExists
Connection = CableModem
Endif
But then I realized that doesn't hold true because if your connected to the cable modem thru a router you can still detect the page, so the thing on the other side of the NIC even though it was a router would still come back as a cable modem.

Hmmmmmm...how to detect what is actually connected to the NIC? Hmmmmmm...