Page 2 of 3
Re: Internet connected or not
Posted: Tue Jun 20, 2017 10:38 am
by chrisjx2002
Very interesting. Thanks for the sharing
Re: Internet connected or not
Posted: Wed Jun 21, 2017 8:29 am
by PeteWG
bpd2000 wrote: ↑Tue Jun 20, 2017 6:16 am
Check Connectivity of Internet based on the result of PING command
You can also use this function to check computer IP in LAN before performing any action to avoid program crash
Interesting code. thanks for sharing!
however I'm a bit sceptical about its reliability, since i got:
"Ping to 0.1.0.1 Succesful"
for
xurl := "0.1.0.1"
(needless to say that doing a C:\>ping 0.1.0.1
(in command line)
returns as expected
"PING: transmission failed. General failure.")
regards,
---
Pete
Re: Internet connected or not
Posted: Wed Jun 21, 2017 9:02 am
by edk
PeteWG wrote: ↑Wed Jun 21, 2017 8:29 am
however I'm a bit sceptical about its reliability, since i got:
"Ping to 0.1.0.1 Succesful"
for
xurl := "0.1.0.1"
(needless to say that doing a C:\>ping 0.1.0.1
(in command line)
returns as expected
"PING: transmission failed. General failure.")
Strange, I've got message
"Internet Connection Not Available" and variable
xerrdescription is 1231. Tested on Win10 32b and HMG 3.4.4
Re: Internet connected or not
Posted: Wed Jun 21, 2017 9:17 am
by PeteWG
KDJ wrote: ↑Mon Jun 19, 2017 8:20 pm
This is probably the simplest way with PINGing:
Code: Select all
FUNCTION Main()
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa384346(v=vs.85).aspx
LOCAL lIsInternet := If(HMG_CallDLL("Wininet.dll", 0, "InternetCheckConnection", "http://www.google.com", 1 /*FLAG_ICC_FORCE_CONNECTION*/, 0) == 1, .T., .F.)
MsgBox("Is internet: " + HB_ValToStr(lIsInternet))
RETURN NIL
Nice suggestion. Thank you very much!
(Although I didn't understand what you mean by "with PINGing").
Now, as a general remark I'd say that DLL calls is not the preffered method, for me, to exploit windows functionality,
when it's easy to implement relevant functions "natively" in harbour.
f.e.:
Code: Select all
PROCEDURE Main
LOCAL isInet := InternetCheckConnection( "https://www.google.com" )
? "=============================="
? "Internet " + If ( isInet, "available!", "not available" )
? InternetCheckConnection() // -> .T. (it works even without Url, as it's documented)
RETURN
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <wininet.h>
HB_FUNC( INTERNETCHECKCONNECTION )
{
const char * cUrl = hb_parc( 1 );
hb_retl( (HB_BOOL) InternetCheckConnection( cUrl, FLAG_ICC_FORCE_CONNECTION, 0 ) );
}
#pragma ENDDUMP
I think this approach is much more faster and safer than calling DLLs.
However I'd like to hear different opinions (if any) on that.
regards,
---
Pete
Re: Internet connected or not
Posted: Wed Jun 21, 2017 9:25 am
by PeteWG
edk wrote: ↑Wed Jun 21, 2017 9:02 am
Strange, I've got message
"Internet Connection Not Available" and variable
xerrdescription is 1231. Tested on Win10 32b and HMG 3.4.4
Really? then it's strange indeed...
Please note that I have built/run the sample using HMG-extended with MinGW32 7.1.0 on Windows 7 pro.
Don't know if it's enough to explain the different results, though. (i'm going to build with HMG official and see..)
Re: Internet connected or not
Posted: Wed Jun 21, 2017 9:35 am
by huiyi_ch
PeteWG wrote: ↑Wed Jun 21, 2017 8:29 am
bpd2000 wrote: ↑Tue Jun 20, 2017 6:16 am
Check Connectivity of Internet based on the result of PING command
You can also use this function to check computer IP in LAN before performing any action to avoid program crash
Interesting code. thanks for sharing!
however I'm a bit sceptical about its reliability, since i got:
"Ping to 0.1.0.1 Succesful"
for
xurl := "0.1.0.1"
(needless to say that doing a C:\>ping 0.1.0.1
(in command line)
returns as expected
"PING: transmission failed. General failure.")
regards,
---
Pete
I've got message "Internet Connection Not Available",too. Tested on WindowsXp 32b and HMG 3.4.4
Re: Internet connected or not
Posted: Wed Jun 21, 2017 9:43 am
by PeteWG
edk wrote: ↑Wed Jun 21, 2017 9:02 am
...Tested on Win10 32b and HMG 3.4.4
Nope! On Win 7 and HMG 3.4.2 and 3.4.3 (i have no installed 3.4.4)
it still gives "Ping to 0.1.0.1 Succesful"
It's very probable the culprit be the "usual suspect" (different Win versions).
regards,
---
Pete
Re: Internet connected or not
Posted: Wed Jun 21, 2017 10:03 am
by PeteWG
huiyi_ch wrote: ↑Wed Jun 21, 2017 9:35 am
I've got message "Internet Connection Not Available",too. Tested on WindowsXp 32b and HMG 3.4.4
Well! i attach the executable i have made with HMG 3.4.3.
Could you please test it to see what it returns on your machine/OS?
regards,
---
Pete
Re: Internet connected or not
Posted: Wed Jun 21, 2017 10:47 am
by edk
Re: Internet connected or not
Posted: Wed Jun 21, 2017 12:13 pm
by bpd2000
I confirm same result as posted by EDK