Does any one know of any cobol code to check if a local pc has an internet connection?
Many thanks
Neil.
If you are just trying to check whether there is an Internet connection and not if a particular site is accessible you can use the following Windows API call. If using from managed code then you need to add a reference to the correct wininet.dll to the project or set using $set ilpinvoke as shown in the example.
where WS-BOOL returned can be: 0 No current Internet connection. 1 There is an Internet connection but the kind is unknown.
Check value of connection-state to determine the specifics where it can be one or more of the following added together:
78 INTERNET_CONNECTION_CONFIGURED value h'40'. *> Local system has a valid connection to the Internet 78 INTERNET_CONNECTION_LAN value h'02'. *> Local system uses a local area network to connect to the Internet. 78 INTERNET_CONNECTION_MODEM value h'01'. *> Local system uses a modem to connect to the Internet. 78 INTERNET_CONNECTION_OFFLINE value h'20'. *> Local system is in offline mode. 78 INTERNET_CONNECTION_PROXY value h'04'. *> Local system uses a proxy server to connect to the Internet. 78 INTERNET_RAS_INSTALLED value h'10'. *> Local system has RAS installed.
$set ilpinvoke"C:\\Windows\\SysWOW64\\wininet.dll" program-id. testconnect. environment division. special-names. call-convention 66 is winapi. working-storage section. 01 connection-state pic 9(9) comp-5 value 0. 01 ws-bool pic s9(9) comp-5 value 0. procedure division.
call winapi "InternetGetConnectedState" using connection-state omitted returning ws-bool end-call.