InternetGetConnectedState_

Just starting out? Need help? Post your questions and find answers here.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

InternetGetConnectedState_

Post by Chirantha »

Its returning 0 even when I'm connected to the internet :( why is this :(
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Karma
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Karma

:lol:
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.
Last edited by SFSxOI on Thu Aug 14, 2008 8:49 pm, edited 1 time in total.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post 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)
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

add this to my other response from your previous post

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

cheers
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.)
Last edited by SFSxOI on Mon Aug 25, 2008 7:43 pm, edited 1 time in total.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post 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.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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...
Post Reply