Gerald,
1) How often do you run/check "Google.com"
2) When checking  the URL, does the code resolve/return the IP, whether good or bad?
Thanks
Paul
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Gerald Kern
Sent: Monday, November 23, 2015 12:50 PM
To: Midrange
Subject: Re: Is there an easy way to monitor for Internet failures?
"Could you do a socket connection?"
That's exactly what I did using one of Scott Klement's client side socket programs. Here is the code. The copybook containing the pr specs is first.
//---------------------------------------------------------------------
      //                Management Information Systems
//---------------------------------------------------------------------
//*********************************************************************
      //               Program Description/Documentation
      //
      // DATE:        1/25/10
      // DESCRIPTION: Check for internet availability.
//*********************************************************************
      // DEFINITION SPECS
//*********************************************************************
     D ZNETISUP_Val    S              1
      // Check for internet availability
     D ZNETISUP        PR             1
     D P#Site                       255    VALUE
     D P#Port                         5  0 VALUE
     D P#Timeout                      5  0
VALUE
     H/Copy Qrpglesrc,OITHSPEC
Note: This is the content of OITHSPEC
  ctl-opt option(*nodebugio:*srcstmt);
  ctl-opt nomain;
  ctl-opt debug(*input);
//---------------------------------------------------------------------
      //                Management Information Systems
//---------------------------------------------------------------------
//*********************************************************************
      //               Program Description/Documentation
      //
      // AUTHOR:      Gerald Kern
      // DATE:        1/25/10
      // DESCRIPTION: Check for internet availability by attempting to
      //  create a socket connection to google.com on port 80. Other sites
      //  using other ports may be passed as parameters. A timeout value
      //  in seconds allows you to specify how long to wait to connect.
      //
      // Programs using this function must include the following
      //  statement in that program's H spec:
      //    H BNDDIR('SOCKTUT/SOCKUTIL')
      //
      //Compile instructions:
      //      1st-Compile this program as a module.
//*********************************************************************
      //       L O G   O F   P R O G R A M   M O D I F I C A T I O N S
//*********************************************************************
      //   Date    Programmer  Description of Modifications
      // --------  ----------
----------------------------------------------
      //XX/XX/XX  XXX         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//*********************************************************************
      // DEFINITION SPECS
//*********************************************************************
     D/copy socktut/qrpglesrc,socket_h
     D/copy socktut/qrpglesrc,errno_h
     D/copy socktut/qrpglesrc,sockutil_h
      // Copybook for ZNETISUP PR specs
     D/Copy Qrpglesrc,ZNETISUPPR
      // Begin prototype procedure
     P ZNETISUP        B                   EXPORT
     D ZNETISUP        PI             1
     D P#Site                       255    VALUE
     D P#Port                         5  0 VALUE
     D P#Timeout                      5  0 VALUE
      //********************************************************
      // end of IFS API call definitions
      //********************************************************
     D sock            S             10I 0
     D port            S              5U 0
     D flags           S             10I 0
     D host            s             32A
     D addr            s             10U 0
     D connto          S                   like(sockaddr_in)
     D err             S             10I 0
     D connfds         S                   like(fdset)
     D timeout         S                   like(timeval)
     D Yes             C                   'Y'
     D No              C                   'N'
      //+++++++++++++++++ M A I N L I N E  C A L C S +++++++++++++++++
      /FREE
       If P#Site = *Blanks;
         P#Site = 'Google.com';
       Endif;
       Host = %Trim(P#Site);
       If P#Port = *Zero;
         P#Port = 80;
       Endif;
       Port = P#Port;
       If P#Timeout = *Zero;
         P#Timeout = 60;
       Endif;
       // Attempt to connect to server...
       Exsr Conn_To_Svr;
       Return ZNETISUP_Val;
       *InLr = *On;
       //++++++++++++++++++++ S U B R O U T I N E S ++++++++++++++++++++
//*********************************************************************
       // Conn_To_Svr - Attempt to establish connection with the server.
       // Assume connection is up and must prove otherwise...
//*********************************************************************
       Begsr Conn_To_Svr;
       ZNETISUP_Val = Yes;
       //************************************************
       // Get the 32-bit network IP address for the host
       //  that was supplied by the user:
       //************************************************
       addr = inet_addr(%trim(host));
       if addr = INADDR_NONE;
         p_hostent = gethostbyname(%trim(host));
         if p_hostent = *NULL;
           ZNETISUP_Val = No;
           LeaveSr;
         endif;
         addr = h_addr;
       endif;
       //************************************************
       // Create a socket
       //************************************************
       sock = socket(AF_INET: SOCK_STREAM:
           IPPROTO_IP);
       if sock < 0;
         ZNETISUP_Val = No;
         LeaveSr;
       endif;
       //************************************************
       // Put the socket in non-blocking mode:
       //************************************************
       flags = fcntl(sock: F_GETFL);
       flags = flags + O_NONBLOCK;
       if fcntl(sock: F_SETFL: flags) < 0;
         ZNETISUP_Val = No;
         LeaveSr;
       endif;
       //************************************************
       // Create a socket address structure that
       //   describes the host & port we wanted to
       //   connect to
       //************************************************
       p_sockaddr = %addr(connto);
       sin_family = AF_INET;
       sin_addr = addr;
       sin_port = port;
       sin_zero = *ALLx'00';
       //************************************************
       // Start the connection process.
       //************************************************
       if connect(sock: %addr(connto):
             %size(connto) ) < 0;
         err = errno;
         if err <> EINPROGRESS;
           callp close(sock);
           ZNETISUP_Val = No;
           LeaveSr;
         endif;
       endif;
       //************************************************
       // wait up to P#Timeout (seconds) for connection to be made
       //************************************************
       FD_ZERO(connfds);
       FD_SET(sock: connfds);
       p_timeval = %addr(timeout);
       tv_sec = P#Timeout;
       tv_usec = 0;
       if select(sock+1: *NULL:
             %addr(connfds):
             *NULL:
             %addr(timeout)) < 0;
         err = errno;
         callp close(sock);
         ZNETISUP_Val = No;
         LeaveSr;
       endif;
       if FD_ISSET(sock: connfds) = *OFF;
         callp close(sock);
         ZNETISUP_Val = No;
         LeaveSr;
       endif;
       // Here we are connected.   We can use send() & recv() to
       // send data here...
       callp close(sock);
       Endsr;
      /END-FREE
//*********************************************************************
     P                 E
      /define ERRNO_LOAD_PROCEDURE
      /copy socktut/qrpglesrc,errno_h
--
Thanks, Jerry
Gerald Kern - Information Technology
Programming Supervisor
IBM Certified RPG IV Developer
Lotus Notes/Domino Administrator
The Toledo Clinic, Inc.
4235 Secor Road
Toledo, OH 43623
Phone 419-479-5535
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: 
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at 
http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.