InternetGetConnectedState_
InternetGetConnectedState_
Its returning 0 even when I'm connected to the internet
why is this 
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
My question to you is what is returning 0, the function or the parameter?msdn wrote:This parameter may return a valid flag even when the function returns FALSE.
Code: Select all
Debug InternetGetConnectedState_(@ics, 0)
Debug icsWhat goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
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.
(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

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
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)
Terry;
This part of your code:
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.)
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
(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

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
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.
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.
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 :
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...
Code: Select all
if CableModemInternalWebpageExists
Connection = CableModem
Endif
Hmmmmmm...how to detect what is actually connected to the NIC? Hmmmmmm...


