Highlighted
Absent Member.
Absent Member.
971 views

Visual Cobol - Check for Internet connection

Jump to solution

Hi,

Does any one know of any cobol code to check if a local pc has an internet connection?

Many thanks

Neil.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol - Check for Internet connection

Jump to solution

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.          

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol - Check for Internet connection

Jump to solution

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.          

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.