Home > Archive > Programming with dBASE > May 2005 > Determine if internet connection exists









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Determine if internet connection exists
Terry Jednaszewski

2005-05-08, 3:23 am

Is there a way that I can determine if an internet connection exists prior to running an ftp file transfer from within an app?

Thanks,
Terry Jednaszewski
Bruce Beacham

2005-05-08, 3:23 am

Terry Jednaszewski wrote:
> Is there a way that I can determine if an internet connection exists prior to running an ftp file transfer from within an app?


Here's a bunch of methods copied from my library, which I assembled from
the kindly provided works of Jim Sare, Rich or Autotracker et al.
Take your pick!



/*A function that allows me to detect whether the user of my program
has an open connection to the internet at the moment of checking.
As requested by me on the NG 17.2.01
*/
FUNCTION IsConnected
/*
Check connection to internet
returns:
false not connected
true connected via modem/lan
uses:
InternetConnectedSta
te()
Version
1.0 08/29/2000
Programmers:
Romain Strieff [dBVIPS]
*/
// return InternetConnectedSta
te()>0
return InternetConnected()>0


FUNCTION HowConnected

local nFlags, cMethod
cMethod = ""

nFlags = InternetConnected()

if nFlags = 0
cMethod = "Not connected"
endif
if bitAnd(nFlags, 1) # 0 // connected via modem
cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",");
+ " Modem")
endIf
if bitAnd(nFlags, 2) # 0 // connected via Lan/cable
cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",");
+ " Lan/cable")
endif
if bitAnd(nFlags, 3) = 3 // Connected via modem and LAN/cable
cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",") ;
+ " Modem and LAN")
endIf
if bitAnd(nFlags, 16) # 0 // RAS is installed
cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",") + " RAS")
endIf

return cMethod

/* nFUNCTION InternetConnectedSta
te
/*
Check connection to internet
returns:
0 not connected
1 connected via modem
2 connected via Lan/cable
use like this:

if InterNetConnectedSta
te>0
do download
else
do make_connection
endif

Or check the difference between
modem (slow) and Lan(fast) to
decide which actions to start

Version
1.0 08/29/2000
Programmers:
Romain Strieff [dBVIPS]

* /
If type(" InternetGetConnected
State") # "FP"
Extern cLong ;
InternetGetConnected
State;
(cLong,cLong) "wininet.dll"
endif

return InternetGetConnected
State(0,0)
*/


FUNCTION InternetConnected
// Corrected version by Jim Sare which fixes prototyping
// and usage bugs in the original version (author unknown)
// of InternetConnected for InternetGetConnected
State.
// NOTE: This function requires Internet Explorer 4.0 or
// later on the system.
LOCAL nFlags

if type(" InternetGetConnected
State") # "FP"
extern CLOGICAL;
InternetGetConnected
State;
(CPTR CULONG, CULONG) "wininet.dll"
endIf
nFlags = 0 // Setup memvar for returned flags.
//RETURN InternetGetConnected
State(nFlags, 0)

// Flags for InternetGetConnected
State and InternetGetConnected
StateEx
#define INTERNET_CONNECTION_
MODEM 0x01
#define INTERNET_CONNECTION_
LAN 0x02
#define INTERNET_CONNECTION_
PROXY 0x04
#define INTERNET_CONNECTION_
MODEM_BUSY 0x08 /* no longer used */
#define INTERNET_RAS_INSTALL
ED 0x10
#define INTERNET_CONNECTION_
OFFLINE 0x20
#define INTERNET_CONNECTION_
CONFIGURED 0x40

//Instead, something like this should work:

if type("_app.Internet") <> "O"
_app.Internet = new object()
endif
_app.Internet.ConnectedState = ""
if InternetGetConnected
State(nFlags, 0)
if bitAnd(nFlags, 1) # 0 // connected via modem
_app.Internet.ConnectedState += ;
iif(empty(_app.Internet.ConnectedState), "", " / ") + "Modem"
endIf
if bitAnd(nFlags, 2) # 0 // connected via Lan/cable
_app.Internet.ConnectedState += ;
iif(empty(_app.Internet.ConnectedState), "", " / ") + "Lan/cable"
endif
if bitAnd(nFlags, 3) = 3 // Connected via modem and LAN/cable
_app.Internet.ConnectedState += ;
iif(empty(_app.Internet.ConnectedState), "", " / ") + "Modem and LAN"
endIf
if bitAnd(nFlags, 16) # 0 // RAS is installed
_app.Internet.ConnectedState += ;
iif(empty(_app.Internet.ConnectedState), "", " / ") + "RAS"
endIf
else // not connected
endif

? _app.Internet.ConnectedState

return nFlags

/*n function InternetConnected
If type(" InternetGetConnected
State") # "FP"
Extern cLong ;
InternetGetConnected
State;
(cLong,cLong) "wininet.dll"
endif
return InternetGetConnected
State(0,0)>0
*/



FUNCTION IsDestinationReachab
le
*** From Rich, autotracker.com 15/12/2003

parameters cStr
/*
cStr = "www.autotraker.com"
cStr = "\\AutoServer"
? IsDestinationReachab
le(cStr)
cStr = Pointer to a string that specifies the destination.
The destination can be an IP address, a UNC name, or an URL.
*/
if empty(cStr)
cStr = "www.beacham.co.uk"
endif
if type(" IsDestinationReachab
leA") # "FP"
extern cLong IsDestinationReachab
leA(cString,CPTR);
"SENSAPI.DLL" from " IsDestinationReachab
leA"
endif
return IsDestinationReachab
leA(cStr,NULL)#0


FUNCTION InternetCheckConnect
ion
*** From Rich, autotracker.com 15/12/2003

/* Attempts to ping a connection
if successful returns true
if the URL parameter is null,it uses WinInet's internal
server database for the nearest server
URL = "http://www.autotraker.com"
? CheckInternetConnect
ion(URL)
? CheckInternetConnect
ion()
*/
parameters URL
if pcount() = 0
//
URL = NULL
endif
#define FLAG_ICC_FORCE_CONNE
CTION 1
if type(" InternetCheckConnect
ionA") # "FP"
extern cLong InternetCheckConnect
ionA(cString,;
cLong,cLong) "wininet.dll" from " InternetCheckConnect
ionA"
endif
return InternetCheckConnect
ionA(URL,FLAG_ICC_FO
RCE_CONNECTION,0) = 1
Terry Jednaszewski

2005-05-08, 8:23 pm

Thanks, Bruce. Just what I was looking for.

Terry

Bruce Beacham Wrote:

> Terry Jednaszewski wrote:
>
> Here's a bunch of methods copied from my library, which I assembled from
> the kindly provided works of Jim Sare, Rich or Autotracker et al.
> Take your pick!
>
>
>
> /*A function that allows me to detect whether the user of my program
> has an open connection to the internet at the moment of checking.
> As requested by me on the NG 17.2.01
> */
> FUNCTION IsConnected
> /*
> Check connection to internet
> returns:
> false not connected
> true connected via modem/lan
> uses:
> InternetConnectedSta
te()
> Version
> 1.0 08/29/2000
> Programmers:
> Romain Strieff [dBVIPS]
> */
> // return InternetConnectedSta
te()>0
> return InternetConnected()>0
>
>
> FUNCTION HowConnected
>
> local nFlags, cMethod
> cMethod = ""
>
> nFlags = InternetConnected()
>
> if nFlags = 0
> cMethod = "Not connected"
> endif
> if bitAnd(nFlags, 1) # 0 // connected via modem
> cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",");
> + " Modem")
> endIf
> if bitAnd(nFlags, 2) # 0 // connected via Lan/cable
> cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",");
> + " Lan/cable")
> endif
> if bitAnd(nFlags, 3) = 3 // Connected via modem and LAN/cable
> cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",") ;
> + " Modem and LAN")
> endIf
> if bitAnd(nFlags, 16) # 0 // RAS is installed
> cMethod = ltrim(cMethod + iif(empty(cMethod), "", ",") + " RAS")
> endIf
>
> return cMethod
>
> /* nFUNCTION InternetConnectedSta
te
> /*
> Check connection to internet
> returns:
> 0 not connected
> 1 connected via modem
> 2 connected via Lan/cable
> use like this:
>
> if InterNetConnectedSta
te>0
> do download
> else
> do make_connection
> endif
>
> Or check the difference between
> modem (slow) and Lan(fast) to
> decide which actions to start
>
> Version
> 1.0 08/29/2000
> Programmers:
> Romain Strieff [dBVIPS]
>
> * /
> If type(" InternetGetConnected
State") # "FP"
> Extern cLong ;
> InternetGetConnected
State;
> (cLong,cLong) "wininet.dll"
> endif
>
> return InternetGetConnected
State(0,0)
> */
>
>
> FUNCTION InternetConnected
> // Corrected version by Jim Sare which fixes prototyping
> // and usage bugs in the original version (author unknown)
> // of InternetConnected for InternetGetConnected
State.
> // NOTE: This function requires Internet Explorer 4.0 or
> // later on the system.
> LOCAL nFlags
>
> if type(" InternetGetConnected
State") # "FP"
> extern CLOGICAL;
> InternetGetConnected
State;
> (CPTR CULONG, CULONG) "wininet.dll"
> endIf
> nFlags = 0 // Setup memvar for returned flags.
> //RETURN InternetGetConnected
State(nFlags, 0)
>
> // Flags for InternetGetConnected
State and InternetGetConnected
StateEx
> #define INTERNET_CONNECTION_
MODEM 0x01
> #define INTERNET_CONNECTION_
LAN 0x02
> #define INTERNET_CONNECTION_
PROXY 0x04
> #define INTERNET_CONNECTION_
MODEM_BUSY 0x08 /* no longer used */
> #define INTERNET_RAS_INSTALL
ED 0x10
> #define INTERNET_CONNECTION_
OFFLINE 0x20
> #define INTERNET_CONNECTION_
CONFIGURED 0x40
>
> //Instead, something like this should work:
>
> if type("_app.Internet") <> "O"
> _app.Internet = new object()
> endif
> _app.Internet.ConnectedState = ""
> if InternetGetConnected
State(nFlags, 0)
> if bitAnd(nFlags, 1) # 0 // connected via modem
> _app.Internet.ConnectedState += ;
> iif(empty(_app.Internet.ConnectedState), "", " / ") + "Modem"
> endIf
> if bitAnd(nFlags, 2) # 0 // connected via Lan/cable
> _app.Internet.ConnectedState += ;
> iif(empty(_app.Internet.ConnectedState), "", " / ") + "Lan/cable"
> endif
> if bitAnd(nFlags, 3) = 3 // Connected via modem and LAN/cable
> _app.Internet.ConnectedState += ;
> iif(empty(_app.Internet.ConnectedState), "", " / ") + "Modem and LAN"
> endIf
> if bitAnd(nFlags, 16) # 0 // RAS is installed
> _app.Internet.ConnectedState += ;
> iif(empty(_app.Internet.ConnectedState), "", " / ") + "RAS"
> endIf
> else // not connected
> endif
>
> ? _app.Internet.ConnectedState
>
> return nFlags
>
> /*n function InternetConnected
> If type(" InternetGetConnected
State") # "FP"
> Extern cLong ;
> InternetGetConnected
State;
> (cLong,cLong) "wininet.dll"
> endif
> return InternetGetConnected
State(0,0)>0
> */
>
>
>
> FUNCTION IsDestinationReachab
le
> *** From Rich, autotracker.com 15/12/2003
>
> parameters cStr
> /*
> cStr = "www.autotraker.com"
> cStr = "\\AutoServer"
> ? IsDestinationReachab
le(cStr)
> cStr = Pointer to a string that specifies the destination.
> The destination can be an IP address, a UNC name, or an URL.
> */
> if empty(cStr)
> cStr = "www.beacham.co.uk"
> endif
> if type(" IsDestinationReachab
leA") # "FP"
> extern cLong IsDestinationReachab
leA(cString,CPTR);
> "SENSAPI.DLL" from " IsDestinationReachab
leA"
> endif
> return IsDestinationReachab
leA(cStr,NULL)#0
>
>
> FUNCTION InternetCheckConnect
ion
> *** From Rich, autotracker.com 15/12/2003
>
> /* Attempts to ping a connection
> if successful returns true
> if the URL parameter is null,it uses WinInet's internal
> server database for the nearest server
> URL = "http://www.autotraker.com"
> ? CheckInternetConnect
ion(URL)
> ? CheckInternetConnect
ion()
> */
> parameters URL
> if pcount() = 0
> //
> URL = NULL
> endif
> #define FLAG_ICC_FORCE_CONNE
CTION 1
> if type(" InternetCheckConnect
ionA") # "FP"
> extern cLong InternetCheckConnect
ionA(cString,;
> cLong,cLong) "wininet.dll" from " InternetCheckConnect
ionA"
> endif
> return InternetCheckConnect
ionA(URL,FLAG_ICC_FO
RCE_CONNECTION,0) = 1


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com