Internet connected or not

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Internet connected or not

Post by chrisjx2002 »

Very interesting. Thanks for the sharing
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Internet connected or not

Post 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
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Internet connected or not

Post 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
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Internet connected or not

Post 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
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Internet connected or not

Post 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..)
huiyi_ch
Posts: 172
Joined: Sat May 21, 2016 5:27 am

Re: Internet connected or not

Post 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
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Internet connected or not

Post 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
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: Internet connected or not

Post 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
Attachments
ping.zip
(1.44 MiB) Downloaded 230 times
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Internet connected or not

Post by edk »

"Internet Connection Not Available" on Win10 Pro 32 and WinXp on VM and Server2012r2
WinXp on VM.PNG
WinXp on VM.PNG (14.96 KiB) Viewed 5463 times
Win10.png
Win10.png (5.22 KiB) Viewed 5463 times
Serwer2012R2.png
Serwer2012R2.png (6.38 KiB) Viewed 5461 times
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Internet connected or not

Post by bpd2000 »

I confirm same result as posted by EDK
BPD
Convert Dream into Reality through HMG
Post Reply