Announcement

Collapse
No announcement yet.

gui monitor network connection up/down

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • gui monitor network connection up/down

    this program is not all my own doing and when you look at my code, i bet nobody else will claim it is theirs either.
    the ping stuff came from other users on the pb forum
    i see there is some ICMP API stuff in pbwin10 but my i had to get this done fast
    i basically put the pingstrt program ping code in a gui for a easy to see monitor of green or red colored gui text label

    you can use this code to monitor a single site or you can monitor several sites that will let you know when your network connection is not working.
    you can ping up to 9 sites one after the other. the first ping response gets you a connection.

    you can also diagnose equipment by too but you can just as easily ping a device continuously using the ping statement from any os system.

    we are having internet connection issues so i did this program to help employees see when the connection was working or not.

    this program is not yet ready for the source section

    if you are pinging just one site, then the program will give text on which site in the gui. of course when you are testing your connection to the internet, you need to ping more that one location to be sure that your internet is down.
    command line example internet offsite1.com offsite2.com offsite3.com .....offsite9.com
    if you give the program just one site like, internet offsite1.com, the program will have to fail on 3 pings before it will report a issue with the connection.
    basically, use either one off site internet/intranet location or about 6 off site internet/intranet locations, i would not use less that 6
    if you are testing a single site, then by all means, use the just the one site

    Code:
    'Internet.bas
    'program pings sites to see if the internet is up or down
    'compiled with pbwin 9.04
    #COMPILE EXE
    #DIM ALL
    #INCLUDE ONCE "WIN32API.INC"
    GLOBAL ghDlg   AS DWORD
    GLOBAL glocation() AS STRING
    GLOBAL glocationstring AS STRING
    
    '%IDD_DIALOG1  =  101
    %IDC_LABEL1   = 1001
    TYPE ICMP_OPTIONS
        Ttl             AS BYTE
        Tos             AS BYTE
        Flags           AS BYTE
        OptionsSize     AS BYTE
        OptionsData     AS LONG
    END TYPE
    
    TYPE ICMP_ECHO_REPLY
        Address         AS LONG
        lStatus          AS LONG
        RoundTripTime   AS LONG
        DataSize        AS LONG 'formerly integer
       'Reserved        As Integer
        DataPointer     AS LONG
        Options         AS ICMP_OPTIONS
        sData            AS STRING * 250
    END TYPE
    
    TYPE RTT    'Round Trip Time info
        RTT AS LONG
        ErrorCode AS LONG
        ErrorText AS STRING * 24
    END TYPE
    
    
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    
    DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (BYVAL s AS STRING) AS LONG
    DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile"  () AS LONG
    DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS LONG) AS LONG
    
    DECLARE FUNCTION IcmpSendEcho LIB "icmp.dll" ALIAS "IcmpSendEcho" _
       (BYVAL IcmpHandle AS LONG, _
        BYVAL DestinationAddress AS LONG, _
        BYVAL RequestData AS STRING, _
        BYVAL RequestSize AS LONG, _
        BYVAL RequestOptions AS LONG, _
        ReplyBuffer AS ICMP_ECHO_REPLY, _
        BYVAL ReplySize AS LONG, BYVAL lTimeout AS LONG) AS LONG
    
    
    FUNCTION pinglocation(shost AS STRING) AS LONG
        DIM hPort AS LONG
        DIM dwAddress AS LONG
        DIM ECHO AS ICMP_ECHO_REPLY
        DIM pOptions AS LONG
        DIM ResolvedHost AS STRING
        DIM p AS BYTE PTR
        DIM IP AS DWORD
        DIM TimeOutSecs AS LONG
        DIM Payload AS STRING
        DIM oRTT AS RTT
    
        IF LEN(shost)=0 THEN
            FUNCTION=0
            EXIT FUNCTION
        END IF
    
        TimeOutSecs = 300
        Payload = "abcdefghijklmnop"
    
        'convert the address into a long representation
        dwAddress = inet_addr(sHost)
        'Might be a host name, try to resolve first.
        IF dwAddress = -1 THEN
          HOST ADDR sHost TO IP
          p = VARPTR(IP)
          ResolvedHost = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3])
          dwAddress = inet_addr(ResolvedHost)
          IF dwAddress = -1 THEN    'If still bad then fail
              oRTT.ErrorCode = -1
              oRTT.ErrorText = "DNS Resolution Failure"
              FUNCTION=0
              EXIT FUNCTION
          END IF
        END IF
       'open a port
        hPort = IcmpCreateFile()
        IF hPort THEN
            'ping it.
            CALL IcmpSendEcho(hPort, dwAddress, payload, LEN(payload), pOptions, ECHO, LEN(ECHO), TimeOutSecs)
            'return the status as ping succes and close
            oRTT.ErrorCode = ECHO.lstatus
            oRTT.RTT = ECHO.RoundTripTime
            CALL IcmpCloseHandle(hPort)
        END IF
    
        IF oRTT.errorcode=0 THEN
            FUNCTION=1   'success
            ELSE
            FUNCTION=0   'failure
        END IF
    END FUNCTION
    
    THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
    LOCAL IRESULT AS LONG
    LOCAL  i AS LONG
    LOCAL lupdown AS LONG
    LOCAL stimeupdown AS STRING
    lupdown=-1
    stimeupdown=""
    startloop:
    FOR i=1 TO 9
    IF LEN(glocation(i))=0 THEN ITERATE
    'IF glocation(i)=glocation(i-1) THEN SLEEP 250
    IRESULT=Pinglocation(glocation(i))
    IF iresult THEN EXIT FOR
    NEXT i
    IF iresult THEN
         IF lupdown<>1 THEN stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
          CONTROL SET COLOR ghDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
          CONTROL SET TEXT ghDlg, %IDC_LABEL1, glocationstring+" UP "+stimeupdown
          DIALOG SET TEXT ghDlg, UCASE$(glocationstring)+" UP"
          UPDATEWINDOW ghDlg
       ELSE
         IF lupdown<>0 THEN stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
         CONTROL SET COLOR ghDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
         CONTROL SET TEXT ghDlg, %IDC_LABEL1, glocationstring+" down "+stimeupdown
         DIALOG SET TEXT ghDlg, LCASE$(glocationstring)+" down "
         UPDATEWINDOW ghDlg
         END IF
    
    SLEEP 3000
    GOTO startloop
    
    END FUNCTION
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
    SELECT CASE AS LONG CBMSG
     CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
     CASE %WM_SYSCOMMAND
                 IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                  LOCAL Res AS LONG
                  Res = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 , "Network monitoring program using ping")
                    IF Res = %IDYES THEN
                      DIALOG END CB.HNDL
                      ELSE
                      FUNCTION = 1
                     EXIT FUNCTION
                    END IF
                  END IF
     END SELECT
    END FUNCTION
    
    
    
    FUNCTION PBMAIN()
       LOCAL i AS LONG
       DIM glocation(0 TO 9) AS STRING
       IF LEN(TRIM$(COMMAND$))=0 THEN
          MSGBOX "You must place url locations or ip addresses to ping on the command tail."+$CRLF+_
                 "Up to 9 different locations can be used to check for ping response."+$CRLF+_
                 "The first location to respond means you have a network connection(green)."
          EXIT FUNCTION
       END IF
       FOR i=1 TO 9
          glocation(i)=LCASE$(TRIM$(COMMAND$(i)))
       NEXT i
       IF LEN(TRIM$(COMMAND$(2)))=0 THEN
           glocationstring=glocation(1)
           glocation(2)=glocation(1)
           glocation(3)=glocation(1)
           ELSE
           glocationstring="Internet"
       END IF
    
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    
    
    
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
      '  LOCAL ghDlg   AS DWORD
        LOCAL hFont1 AS DWORD
        LOCAL counter AS LONG
        LOCAL hthread AS DWORD
        LOCAL lresult AS LONG
        LOCAL lwidth AS LONG
        lwidth=82
        IF LEN(COMMAND$(2))=0 THEN
            lwidth=LEN(glocation(1))
            IF lwidth THEN lwidth=lwidth*8
            IF lwidth<82 THEN lwidth=82
            IF lwidth>676 THEN lwidth=676
        END IF
        lwidth=lwidth+28
        
        DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
            OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
            OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
            %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
            %WS_EX_RIGHTSCROLLBAR, TO ghDlg
        CONTROL ADD LABEL, ghDlg, %IDC_LABEL1, " Starting ver 1.02", 0, 0, 670, 12, _
            %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
            %WS_EX_LTRREADING
    
        FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
        CONTROL SET FONT ghDlg, %IDC_LABEL1, hFont1
        THREAD CREATE pingtest(1&) TO hThread
        DO WHILE hthread = 0
         SLEEP 150
        LOOP
        DIALOG SHOW MODAL ghDlg  , CALL ShowDIALOG1Proc TO lRslt
        FONT END hFont1
        FUNCTION = lRslt
    END FUNCTION
    Attached Files
    Last edited by Paul Purvis; 22 Mar 2012, 12:59 AM.
    p purvis

  • #2
    i did some testing and updated the code
    some things where too slow for me

    major changes where
    the gui has a wider startup window if you are just pinging one site and that site name is longer that a few characters.
    changed TimeOutSecs = 2000 changed to 300
    removed sleep states during pinging sites
    changed the time period in the loop of pinging sites down to 3 seconds from 5 seconds
    it would be nice to have a command parameter where the time between pings could be adjusted, but 3 seconds is not running up my single cpu processor
    this program was written for monitoring bad connections and not just the day to day stuff, if you want the day to day stuff, increase the loop time to more than 3 seconds and if you have go over long delays, the increase the timeoutsecs to something higher

    i am likely coding things wrong more that likely , but it seems to be working

    Opps, left in a statement i was using to debug it. removed it and added a time stamp for when up and down occurred.
    Last edited by Paul Purvis; 22 Mar 2012, 01:01 AM.
    p purvis

    Comment


    • #3
      i do not use any windows servers or windows 7 at this time, but those that do may want to know about this this hotfix from microsoft is
      it is concerning tcp autotuning and how it might get turned off by windows computers accessing a server that do not use autotuning.

      http://support.microsoft.com/default...b;EN-US;983528
      p purvis

      Comment


      • #4
        WOW
        in vista and up, see registry tcpip setting for NetworkThrottlingIndex

        for the life of me, you would think the user should be able to have access to
        a control panel that would have a slider index to make these kinds of changes in vista os and up

        http://www.speedguide.net/articles/w...08-tweaks-2574
        p purvis

        Comment


        • #5
          updated the above networking/internet connection monitoring ping program

          added a log report and displaying the log in a msgbox by clicking on the text of the current status

          also found some code that unnecessarily sent the status to a control labale even if the status had not changed, basically reducing cpu and gui usage.

          Code:
          'Internet.bas
          'program pings sites to see if the internet is up or down
          'compiled with pbwin 9.04
          #COMPILE EXE
          #DIM ALL
          #INCLUDE ONCE "WIN32API.INC"
          GLOBAL ghDlg   AS DWORD
          GLOBAL glocation() AS STRING
          GLOBAL glocationstring AS STRING
          GLOBAL gmessagetext1 AS STRING ' holds the locations being pinged
          GLOBAL gmessagetext2 AS STRING ' holds the log on pinging locations being up or down as a group
          
          '%IDD_DIALOG1  =  101
          %IDC_LABEL1   = 1001
          TYPE ICMP_OPTIONS
              Ttl             AS BYTE
              Tos             AS BYTE
              Flags           AS BYTE
              OptionsSize     AS BYTE
              OptionsData     AS LONG
          END TYPE
          
          TYPE ICMP_ECHO_REPLY
              Address         AS LONG
              lStatus          AS LONG
              RoundTripTime   AS LONG
              DataSize        AS LONG 'formerly integer
             'Reserved        As Integer
              DataPointer     AS LONG
              Options         AS ICMP_OPTIONS
              sData            AS STRING * 250
          END TYPE
          
          TYPE RTT    'Round Trip Time info
              RTT AS LONG
              ErrorCode AS LONG
              ErrorText AS STRING * 24
          END TYPE
          
          
          DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
          DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
          
          DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (BYVAL s AS STRING) AS LONG
          DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile"  () AS LONG
          DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS LONG) AS LONG
          
          DECLARE FUNCTION IcmpSendEcho LIB "icmp.dll" ALIAS "IcmpSendEcho" _
             (BYVAL IcmpHandle AS LONG, _
              BYVAL DestinationAddress AS LONG, _
              BYVAL RequestData AS STRING, _
              BYVAL RequestSize AS LONG, _
              BYVAL RequestOptions AS LONG, _
              ReplyBuffer AS ICMP_ECHO_REPLY, _
              BYVAL ReplySize AS LONG, BYVAL lTimeout AS LONG) AS LONG
          
          
          FUNCTION pinglocation(shost AS STRING) AS LONG
              DIM hPort AS LONG
              DIM dwAddress AS LONG
              DIM ECHO AS ICMP_ECHO_REPLY
              DIM pOptions AS LONG
              DIM ResolvedHost AS STRING
              DIM p AS BYTE PTR
              DIM IP AS DWORD
              DIM TimeOutSecs AS LONG
              DIM Payload AS STRING
              DIM oRTT AS RTT
          
              IF LEN(shost)=0 THEN
                  FUNCTION=0
                  EXIT FUNCTION
              END IF
          
              TimeOutSecs = 300
              Payload = "abcdefghijklmnop"
          
              'convert the address into a long representation
              dwAddress = inet_addr(sHost)
              'Might be a host name, try to resolve first.
              IF dwAddress = -1 THEN
                HOST ADDR sHost TO IP
                p = VARPTR(IP)
                ResolvedHost = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3])
                dwAddress = inet_addr(ResolvedHost)
                IF dwAddress = -1 THEN    'If still bad then fail
                    oRTT.ErrorCode = -1
                    oRTT.ErrorText = "DNS Resolution Failure"
                    FUNCTION=0
                    EXIT FUNCTION
                END IF
              END IF
             'open a port
              hPort = IcmpCreateFile()
              IF hPort THEN
                  'ping it.
                  CALL IcmpSendEcho(hPort, dwAddress, payload, LEN(payload), pOptions, ECHO, LEN(ECHO), TimeOutSecs)
                  'return the status as ping succes and close
                  oRTT.ErrorCode = ECHO.lstatus
                  oRTT.RTT = ECHO.RoundTripTime
                  CALL IcmpCloseHandle(hPort)
              END IF
          
              IF oRTT.errorcode=0 THEN
                  FUNCTION=1   'success
                  ELSE
                  FUNCTION=0   'failure
              END IF
          END FUNCTION
          
          THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
          LOCAL IRESULT AS LONG
          LOCAL  i AS LONG
          LOCAL lupdown AS LONG
          LOCAL stimeupdown AS STRING
          lupdown=-1
          stimeupdown=""
          startloop:
          FOR i=1 TO 9
          IF LEN(glocation(i))=0 THEN ITERATE
          'IF glocation(i)=glocation(i-1) THEN SLEEP 250
          IRESULT=Pinglocation(glocation(i))
          IF iresult THEN EXIT FOR
          NEXT i
          IF iresult THEN
               IF lupdown<>1 THEN
                 stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
                CONTROL SET COLOR ghDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                CONTROL SET TEXT ghDlg, %IDC_LABEL1, glocationstring+" UP "+stimeupdown
                DIALOG SET TEXT ghDlg, UCASE$(glocationstring)+" UP"
                UPDATEWINDOW ghDlg
                gmessagetext2+=DATE$+" "+TIME$+" status is UP"+$CRLF
                END IF
             ELSE
               IF lupdown<>0 THEN
               stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
               CONTROL SET COLOR ghDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
               CONTROL SET TEXT ghDlg, %IDC_LABEL1, glocationstring+" down "+stimeupdown
               DIALOG SET TEXT ghDlg, LCASE$(glocationstring)+" down "
               UPDATEWINDOW ghDlg
               gmessagetext2+=DATE$+" "+TIME$+" status is down"+$CRLF+"--------------------------------------------"+$CRLF
               END IF
          END IF
          
          SLEEP 3000
          GOTO startloop
          
          END FUNCTION
          
          CALLBACK FUNCTION ShowDIALOG1Proc()
          SELECT CASE AS LONG CBMSG
           CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
           CASE %WM_SYSCOMMAND
                       IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                        LOCAL Res AS LONG
                        Res = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 , "Network monitoring program using ping")
                          IF Res = %IDYES THEN
                            DIALOG END CB.HNDL
                            ELSE
                            FUNCTION = 1
                           EXIT FUNCTION
                          END IF
                        END IF
           CASE  %WM_COMMAND
               IF CB.CTL =  %IDC_LABEL1 AND CB.CTLMSG = %STN_Clicked THEN  MSGBOX gmessagetext1+gmessagetext2,%MB_OK,"Log report of Network monitoring program using ping"
           
               
           
          
           END SELECT
          
          END FUNCTION
          
          
          
          FUNCTION PBMAIN()
             LOCAL i AS LONG
             DIM glocation(0 TO 9) AS STRING
             IF LEN(TRIM$(COMMAND$))=0 THEN
                MSGBOX "You must place url locations or ip addresses to ping on the command tail."+$CRLF+_
                       "Up to 9 different locations can be used to check for ping response."+$CRLF+_
                       "The first location to respond means you have a network connection(green)."
                EXIT FUNCTION
             END IF
               gmessagetext1="Locations used for Network monitoring program using ping"+$CRLF
              
             FOR i=1 TO 9
                glocation(i)=LCASE$(TRIM$(COMMAND$(i)))
                IF LEN (glocation(i)) THEN gmessagetext1+=glocation(i)+$CRLF
             NEXT i
             IF LEN(TRIM$(COMMAND$(2)))=0 THEN
                 glocationstring=glocation(1)
                 glocation(2)=glocation(1)
                 glocation(3)=glocation(1)
                 ELSE
                 glocationstring="Internet"
             END IF
             gmessagetext2=$CRLF+"Log report"+$CRLF+"======================"+$CRLF
             
              ShowDIALOG1 %HWND_DESKTOP
          END FUNCTION
          
          
          
          FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
              LOCAL lRslt  AS LONG
            '  LOCAL ghDlg   AS DWORD
              LOCAL hFont1 AS DWORD
              LOCAL counter AS LONG
              LOCAL hthread AS DWORD
              LOCAL lresult AS LONG
              LOCAL lwidth AS LONG
              lwidth=82
              IF LEN(COMMAND$(2))=0 THEN
                  lwidth=LEN(glocation(1))
                  IF lwidth THEN lwidth=lwidth*8
                  IF lwidth<82 THEN lwidth=82
                  IF lwidth>676 THEN lwidth=676
              END IF
              lwidth=lwidth+28
          
              DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
                  OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
                  OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                  %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                  %WS_EX_RIGHTSCROLLBAR, TO ghDlg
              CONTROL ADD LABEL, ghDlg, %IDC_LABEL1, " Starting ver 1.02", 0, 0, 670, 12, _
                 %SS_NOTIFY OR  %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
                  %WS_EX_LTRREADING
          
              FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
              CONTROL SET FONT ghDlg, %IDC_LABEL1, hFont1
              THREAD CREATE pingtest(1&) TO hThread
              DO WHILE hthread = 0
               SLEEP 150
              LOOP
              DIALOG SHOW MODAL ghDlg  , CALL ShowDIALOG1Proc TO lRslt
              FONT END hFont1
              FUNCTION = lRslt
          END FUNCTION
          Attached Files
          p purvis

          Comment


          • #6
            another upgrade
            this version allows for 1000 sites to ping, lol
            this program is probably what most are wanting

            in this program

            if you want to ping a certain site more than one time, before the program reports a failure, then you have to place the site to ping on the command tail that number of times to ping before this program reports a downed site
            such as INTERNET google.com google.com, this will only try to ping google.com twice before reporting a problem
            take if form me, you probably want to ping any internet site at least 4 times before you get a no response from a ping, three is good by a couple of times, all three will fail to respond during the day
            but that is easy to see in the log report because you can see where the next loop of pings catches possible responses from the site.


            also you can change the timing
            timing before the program actually starts pinging sites in cause you want to do that in a boot up situation and do not want any negative or false reports
            timing between pinging a sites if you have more than one site
            timing in the ping timeout function
            timing in how long before the sites are pinged in the group(loop timing)

            even though you can change the ICMP timeout(to even a ridicules small number timeout number) , pinging the internet with a value of less that 100, is probably foolish.
            but if you want to do some tight testing, it is built in so you can adjust those timeout number of the ICMP function.
            you can possible do a small timeout number on a lan location and even a smaller number should work (i have not had to do troubleshooting yet on my lan).

            also you can send the msgbox that holds a better log report to the clipboard
            sorry folks, i do not have a textbox yet, i am still working on getting the main job of the program functional

            i need to get a source formater, sorry



            Code:
            'Internet.bas
            'program pings sites to see if the internet is up or down using ICMP
            'compiled with pbwin 9.04
            #COMPILE EXE
            #DIM ALL
            #INCLUDE ONCE "WIN32API.INC"
            GLOBAL g_hDlg   AS DWORD
            GLOBAL g_slocation() AS STRING
            GLOBAL g_slocationstring AS STRING
            GLOBAL g_smessagetext1 AS STRING ' holds the log report header plus the locations pinged
            GLOBAL g_smessagetext2 AS STRING ' holds the log on pinging locations being up or down as a group
            GLOBAL g_smessagetext3 AS STRING ' holds the log report ending
            
            GLOBAL g_itimeout AS LONG
            GLOBAL g_iloopdelay AS LONG
            GLOBAL g_itdelay AS LONG
            GLOBAL g_ispaceingoficmp AS LONG
            GLOBAL g_iicmplocations  AS LONG
            GLOBAL g_iicmpmade AS LONG
            GLOBAL g_iloopsmade AS LONG
            
            
            
            '%IDD_DIALOG1  =  101
            %IDC_LABEL1   = 1001
            TYPE ICMP_OPTIONS
                Ttl             AS BYTE
                Tos             AS BYTE
                Flags           AS BYTE
                OptionsSize     AS BYTE
                OptionsData     AS LONG
            END TYPE
            
            TYPE ICMP_ECHO_REPLY
                Address         AS LONG
                lStatus          AS LONG
                RoundTripTime   AS LONG
                DataSize        AS LONG 'formerly integer
               'Reserved        As Integer
                DataPointer     AS LONG
                Options         AS ICMP_OPTIONS
                sData            AS STRING * 250
            END TYPE
            
            TYPE RTT    'Round Trip Time info
                RTT AS LONG
                ErrorCode AS LONG
                ErrorText AS STRING * 24
            END TYPE
            
            
            DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
            
            DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
            
            DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (BYVAL s AS STRING) AS LONG
            DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile"  () AS LONG
            DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS LONG) AS LONG
            
            DECLARE FUNCTION IcmpSendEcho LIB "icmp.dll" ALIAS "IcmpSendEcho" _
               (BYVAL IcmpHandle AS LONG, _
                BYVAL DestinationAddress AS LONG, _
                BYVAL RequestData AS STRING, _
                BYVAL RequestSize AS LONG, _
                BYVAL RequestOptions AS LONG, _
                ReplyBuffer AS ICMP_ECHO_REPLY, _
                BYVAL ReplySize AS LONG, BYVAL lTimeout AS LONG) AS LONG
            
            
            FUNCTION pinglocation(shost AS STRING) AS LONG
                DIM hPort AS LONG
                DIM dwAddress AS LONG
                DIM ECHO AS ICMP_ECHO_REPLY
                DIM pOptions AS LONG
                DIM ResolvedHost AS STRING
                DIM p AS BYTE PTR
                DIM IP AS DWORD
                DIM TimeOutSecs AS LONG
                DIM Payload AS STRING
                DIM oRTT AS RTT
            
                IF LEN(shost)=0 THEN
                    FUNCTION=0
                    EXIT FUNCTION
                END IF
            
                TimeOutSecs = g_itimeout
                Payload = "abcdefghijklmnop"
            
                'convert the address into a long representation
                dwAddress = inet_addr(sHost)
                'Might be a host name, try to resolve first.
                IF dwAddress = -1 THEN
                  HOST ADDR sHost TO IP
                  p = VARPTR(IP)
                  ResolvedHost = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3])
                  dwAddress = inet_addr(ResolvedHost)
                  IF dwAddress = -1 THEN    'If still bad then fail
                      oRTT.ErrorCode = -1
                      oRTT.ErrorText = "DNS Resolution Failure"
                      FUNCTION=0
                      EXIT FUNCTION
                  END IF
                END IF
               'open a port
                hPort = IcmpCreateFile()
                IF hPort THEN
                    'ping it.
                    CALL IcmpSendEcho(hPort, dwAddress, payload, LEN(payload), pOptions, ECHO, LEN(ECHO), TimeOutSecs)
                    'return the status as ping succes and close
                    oRTT.ErrorCode = ECHO.lstatus
                    oRTT.RTT = ECHO.RoundTripTime
                    CALL IcmpCloseHandle(hPort)
                END IF
            
                IF oRTT.errorcode=0 THEN
                    FUNCTION=1   'success
                    ELSE
                    FUNCTION=0   'failure
                END IF
            END FUNCTION
            
            THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
            LOCAL IRESULT AS LONG
            LOCAL  i AS LONG
            LOCAL lupdown AS LONG
            LOCAL stimeupdown AS STRING
            lupdown=-1
            stimeupdown=""
            startloop:
            FOR i=1 TO g_iicmplocations
            IRESULT=Pinglocation(g_slocation(i))
            IF iresult THEN INCR g_iicmpmade:EXIT FOR
            IF g_itimeout THEN SLEEP g_itimeout
            NEXT i
            IF iresult THEN
                 IF lupdown<>1 THEN
                   stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
                  CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                  CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" UP "+stimeupdown
                  DIALOG SET TEXT g_hDlg, UCASE$(g_slocationstring)+" UP"
                  UPDATEWINDOW g_hDlg
                  g_smessagetext2+=DATE$+" "+TIME$+" status is UP"+$CRLF
                  END IF
               ELSE
                 IF lupdown<>0 THEN
                 stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
                 CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
                 CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" down "+stimeupdown
                 DIALOG SET TEXT g_hDlg, LCASE$(g_slocationstring)+" down "
                 UPDATEWINDOW g_hDlg
                 g_smessagetext2+="--------------------------------------------"+$CRLF+DATE$+" "+TIME$+" status is down"+$CRLF
                 END IF
            END IF
            INCR  g_iloopsmade
            
            SLEEP g_iloopdelay
            GOTO startloop
            END FUNCTION
            
            FUNCTION sendtoclipboard() AS LONG
                LOCAL sTEMP AS STRING
                DO
                CLIPBOARD RESET
                CLIPBOARD GET TEXT STEMP
                IF LEN(STEMP)=0 THEN EXIT LOOP
                LOOP
                CLIPBOARD SET  TEXT g_smessagetext1+g_smessagetext2+g_smessagetext3
            END FUNCTION
            
            
            CALLBACK FUNCTION ShowDIALOG1Proc()
            LOCAL itoclipboard AS LONG
            
            SELECT CASE AS LONG CBMSG
             CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
             CASE %WM_SYSCOMMAND
                         IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                          LOCAL Res AS LONG
                          Res = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 , "ICMP monitoring program")
                            IF Res = %IDYES THEN
                              DIALOG END CB.HNDL
                              ELSE
                              FUNCTION = 1
                             EXIT FUNCTION
                            END IF
                          END IF
             CASE  %WM_COMMAND
                 IF CB.CTL =  %IDC_LABEL1 AND CB.CTLMSG = %STN_Clicked THEN
                      g_smessagetext3="======================"+$CRLF+DATE$+" "+TIME$+" Log report end"+$CRLF+$CRLF
                      g_smessagetext3+="Loops made trying     ="+STR$(g_iloopsmade)+$CRLF
                      g_smessagetext3+="Loops with repsonses  ="+STR$(g_iicmpmade)+$CRLF
                      g_smessagetext3+="Loops with failures   ="+STR$(g_iloopsmade-g_iicmpmade)+$CRLF
                      itoclipboard=MSGBOX(g_smessagetext1+g_smessagetext2+g_smessagetext3+$CRLF+$CRLF+_
                         "Any button closes this log report."+$CRLF+_
                         "Send this ICMP log report to the clipboard?",%MB_OKCANCEL OR  %MB_DEFBUTTON1 OR  %MB_ICONMASK,_
                         "ICMP monitoring program log report")
                      IF itoclipboard=%IDOK  THEN sendtoclipboard
                 END IF
            
             END SELECT
            
            END FUNCTION
            
            
            
            FUNCTION PBMAIN()
               processstartup
               IF g_iicmplocations=0 THEN EXIT FUNCTION
               ShowDIALOG1 %HWND_DESKTOP
            END FUNCTION
            
            
            
            FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                LOCAL lRslt  AS LONG
              '  LOCAL ghDlg   AS DWORD
                LOCAL hFont1 AS DWORD
                LOCAL counter AS LONG
                LOCAL hthread AS DWORD
                LOCAL lresult AS LONG
                LOCAL lwidth AS LONG
                lwidth=82
                IF LEN(COMMAND$(2))=0 THEN
                    lwidth=LEN(g_slocation(1))
                    IF lwidth THEN lwidth=lwidth*8
                    IF lwidth<82 THEN lwidth=82
                    IF lwidth>676 THEN lwidth=676
                END IF
                lwidth=lwidth+28
            
                DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
                    OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
                    OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                    %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                    %WS_EX_RIGHTSCROLLBAR, TO g_hDlg
                CONTROL ADD LABEL, g_hDlg, %IDC_LABEL1, " Starting ver 1.02", 0, 0, 670, 12, _
                   %SS_NOTIFY OR  %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
                    %WS_EX_LTRREADING
            
                FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
                CONTROL SET FONT g_hDlg, %IDC_LABEL1, hFont1
                THREAD CREATE pingtest(1&) TO hThread
                DO WHILE hthread = 0
                 SLEEP 150
                LOOP
                DIALOG SHOW MODAL g_hDlg  , CALL ShowDIALOG1Proc TO lRslt
                FONT END hFont1
                FUNCTION = lRslt
            END FUNCTION
            
            FUNCTION processstartup() AS LONG
            DIM i AS LONG
            DIM j AS LONG
            DIM stemp1 AS STRING
            DIM stemp2 AS STRING
            g_itdelay=0
            g_itimeout=300
            g_iloopdelay=3000
            g_ispaceingoficmp=0
            g_iicmplocations=1000
            
            DIM g_slocation(0 TO g_iicmplocations) AS STRING
            i=0
            DO
            INCR i
            stemp2=LCASE$(TRIM$(COMMAND$(i)))
            IF LEN(stemp2)=0 THEN EXIT DO
            IF stemp2="-d" THEN stemp1=stemp2:ITERATE
            IF stemp2="-t" THEN stemp1=stemp2:ITERATE
            IF stemp2="-s" THEN stemp1=stemp2:ITERATE
            IF stemp2="-l" THEN stemp1=stemp2:ITERATE
            
            IF STEMP1="-d" THEN g_itdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
            IF STEMP1="-t" THEN g_itimeout=ABS(VAL(stemp2)):stemp1="":ITERATE
            IF STEMP1="-s" THEN g_ispaceingoficmp=ABS(VAL(stemp2)):stemp1="":ITERATE
            IF STEMP1="-l" THEN g_iloopdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
            INCR j
            g_slocation(j)=stemp2
            stemp1=""
            IF J=1000 THEN EXIT DO
            LOOP
            g_iicmplocations=J
              IF g_iicmplocations=0 THEN
                  MSGBOX "You must place url locations or ip addresses to ping on the command tail."+$CRLF+_
                         "To test a site for multiple sequential ping tries, repeat the location x times."+$CRLF+_
                         "The first location to respond to a ping means a ICMP connection(green) was made."+$CRLF+$CRLF+_
                         "Extra command tail options can change the pinging function timing in milliseconds."+$CRLF+_
                         " -d millisecond delay before the program starts monitoring sites, default 0"+$CRLF+_
                         " -t millisecond timeout for a single ICMP try at each site, default  300"+$CRLF+_
                         " -s millisecond delay of time before pinging each site after the first site, default 0"+$CRLF+_
                         " -l millisecond delay in loop time before trying the sites again, default 3000", %MB_OK OR %MB_ICONMASK,"ICMP Monitoring program"
            
                  EXIT FUNCTION
               END IF
            
              g_smessagetext1= "If you cannot see the bottom, press enter to send the report to clipboard."+$CRLF
              g_smessagetext1+="or you can close the window with the X button at the top right."+$CRLF+$CRLF
              g_smessagetext1+="Locations and order used in loop for ICMP monitoring program"+$CRLF
            
               FOR i=1 TO g_iicmplocations
                 g_smessagetext1+=TRIM$(STR$(i))+". "+g_slocation(i)+$CRLF
                 IF g_slocation(i)<>"" THEN IF g_slocation(i)<>g_slocation(1) THEN g_slocationstring="Internet"
               NEXT i
               IF g_slocationstring="" THEN g_slocationstring=g_slocation(1)
            
               g_smessagetext1+=$CRLF+"the first response of an ICMP packet creates the status UP"+$CRLF
               g_smessagetext1+="delay before the program starts ICMP monitoring = "+STR$(g_itdelay)+" milliseconds"+$CRLF
               g_smessagetext1+="timeout used for each ICMP packet sent  = "+STR$(g_itimeout)+" milliseconds"+$CRLF
               g_smessagetext1+="time of spaceing between each ping test  = "+STR$(g_ispaceingoficmp)+" milliseconds"+$CRLF
               g_smessagetext1+="loop delay between ICMP testing  = "+STR$(g_iloopdelay)+" milliseconds "+$CRLF
               IF g_itdelay>0 THEN SLEEP g_itdelay
               g_smessagetext2=$CRLF+DATE$+" "+TIME$+" Log report start"+$CRLF+"======================"+$CRLF
            
            END FUNCTION
            Attached Files
            Last edited by Paul Purvis; 30 Mar 2012, 12:41 AM.
            p purvis

            Comment


            • #7
              another update, getting close to the final
              added audible alarms as an option
              added changeable text in the status bar as an option

              i found an intermittent internet problem with a coaxial cable only because a TV that was hooked up and turned on went off, when i was reconnecting the main a coaxial wire leading into our office.
              otherwise, i might not of found the short, because the TV audio and video gave immediate results of a poor signal or none at all.
              i have only spend almost a week and half on this internet issue where there where multiple issues including a cable splitter having gone temperamental.

              so i wanted something like that in my program where a person could use this program to troubleshoot internet issues and this is one of the few times i found using sound might be effective in troubleshooting.

              you can use one of two audible modes
              mode 1. a sound beep when the ping/ICMP returns a response(UP) and and another different sound beep when the ping/ICMP does not return a response(DOWN).
              mode 2. an almost continuous sounding beep only when the status of the ping/icmp status is DOWN. this will help get anybody's attention and a person can work away from the computer on equipment while listening to continuous beeping sound in an effort to troubleshoot a problem.

              now you can also replace the text in the status which is good for non technical people to monitor or where you have the program testing many i ip addresses at the same time.

              i do not know much about programing for sound to do what i really wanted to achieve(something like the TV where no signal would produce no sound immediately or sound immediately with no signal), but this the closest i have gotten with a lot of practice and not wanting to produce a sound that was too harsh on my ears or others ears.

              in order to troubleshoot Ethernet equipment, you will have to set the timing to low numbers and a loop delay to 0(zero). to troubleshoot for a computer connecting to a router, you can use a command line something like this
              programname.exe 192.168.1.1 -t 50 -d 0 -s 0 -bc -v Router1
              and a web site
              programname.exe 65.425.118.65 65.425.118.65 65.425.118.65 65.425.118.65 -t 200 -d 500 -s 100 -bc -v WebsiteName

              if you want the sound and do not want it to be continuous use -b instead of -bc


              Code:
              'Internet.bas
              'program pings sites to see if the internet is up or down using ICMP
              'compiled with pbwin 9.04
              #COMPILE EXE
              #DIM ALL
              #INCLUDE ONCE "WIN32API.INC"
              GLOBAL g_hDlg   AS DWORD
              GLOBAL g_slocation() AS STRING
              GLOBAL g_slocationstring AS STRING
              GLOBAL g_smessagetext0 AS STRING ' message goes on the top of the log report in the msgbox
              GLOBAL g_smessagetext1 AS STRING ' holds the log report header plus the locations pinged
              GLOBAL g_smessagetext2 AS STRING ' holds the log on pinging locations being up or down as a group
              GLOBAL g_smessagetext3 AS STRING ' holds the log report ending
              
              GLOBAL g_itimeout AS LONG
              GLOBAL g_iloopdelay AS LONG
              GLOBAL g_itdelay AS LONG
              GLOBAL g_ispaceingoficmp AS LONG
              GLOBAL g_iicmplocations  AS LONG
              GLOBAL g_iicmpmade AS QUAD
              GLOBAL g_iloopsmade AS QUAD
              GLOBAL g_beepit AS LONG
              GLOBAL g_beepitc AS LONG
              GLOBAL g_beepitsignal AS LONG
              GLOBAL g_itextchange AS LONG
              GLOBAL g_stextchange AS STRING
              
              
              
              '%IDD_DIALOG1  =  101
              %IDC_LABEL1   = 1001
              TYPE ICMP_OPTIONS
                  Ttl             AS BYTE
                  Tos             AS BYTE
                  Flags           AS BYTE
                  OptionsSize     AS BYTE
                  OptionsData     AS LONG
              END TYPE
              
              TYPE ICMP_ECHO_REPLY
                  Address         AS LONG
                  lStatus          AS LONG
                  RoundTripTime   AS LONG
                  DataSize        AS LONG 'formerly integer
                 'Reserved        As Integer
                  DataPointer     AS LONG
                  Options         AS ICMP_OPTIONS
                  sData            AS STRING * 250
              END TYPE
              
              TYPE RTT    'Round Trip Time info
                  RTT AS LONG
                  ErrorCode AS LONG
                  ErrorText AS STRING * 24
              END TYPE
              
              
              DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
              
              DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
              
              DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (BYVAL s AS STRING) AS LONG
              DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile"  () AS LONG
              DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS LONG) AS LONG
              
              DECLARE FUNCTION IcmpSendEcho LIB "icmp.dll" ALIAS "IcmpSendEcho" _
                 (BYVAL IcmpHandle AS LONG, _
                  BYVAL DestinationAddress AS LONG, _
                  BYVAL RequestData AS STRING, _
                  BYVAL RequestSize AS LONG, _
                  BYVAL RequestOptions AS LONG, _
                  ReplyBuffer AS ICMP_ECHO_REPLY, _
                  BYVAL ReplySize AS LONG, BYVAL lTimeout AS LONG) AS LONG
              
              
              FUNCTION pinglocation(shost AS STRING) AS LONG
                  DIM hPort AS LONG
                  DIM dwAddress AS LONG
                  DIM ECHO AS ICMP_ECHO_REPLY
                  DIM pOptions AS LONG
                  DIM ResolvedHost AS STRING
                  DIM p AS BYTE PTR
                  DIM IP AS DWORD
                  DIM TimeOutSecs AS LONG
                  DIM Payload AS STRING
                  DIM oRTT AS RTT
              
                  IF LEN(shost)=0 THEN
                      FUNCTION=0
                      EXIT FUNCTION
                  END IF
              
                  TimeOutSecs = g_itimeout
                  Payload = "abcdefghijklmnop"
              
                  'convert the address into a long representation
                  dwAddress = inet_addr(sHost)
              
                  'Might be a host name, try to resolve first.
                  IF dwAddress = -1 THEN
                    HOST ADDR sHost TO IP
                    p = VARPTR(IP)
                    ResolvedHost = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3])
                    dwAddress = inet_addr(ResolvedHost)
                    IF dwAddress = -1 THEN    'If still bad then fail
                        oRTT.ErrorCode = -1
                        oRTT.ErrorText = "DNS Resolution Failure"
                        FUNCTION=0
                        EXIT FUNCTION
                    END IF
                  END IF
                 'open a port
                  hPort = IcmpCreateFile()
                  IF hPort THEN
                      'ping it.
                      CALL IcmpSendEcho(hPort, dwAddress, payload, LEN(payload), pOptions, ECHO, LEN(ECHO), TimeOutSecs)
                      'return the status as ping succes and close
                      oRTT.ErrorCode = ECHO.lstatus
                      oRTT.RTT = ECHO.RoundTripTime
                      CALL IcmpCloseHandle(hPort)
                  END IF
              
                  IF oRTT.errorcode=0 THEN
                      FUNCTION=1   'success
                      ELSE
                      FUNCTION=0   'failure
                  END IF
              END FUNCTION
              
              THREAD FUNCTION beepit(BYVAL x AS LONG) AS LONG
              DO
              IF g_beepit=2 THEN EXIT DO
              IF g_beepitsignal THEN
                  IF g_beepit=1 THEN
                      IF g_beepitsignal=2 THEN WinBeep 5000,50
                      IF g_beepitsignal=1 THEN WinBeep 100,50
                      g_beepitsignal=0
                  END IF
              END IF
              SLEEP 1
              
              LOOP
              END FUNCTION
              
              THREAD FUNCTION beepitc(BYVAL x AS LONG) AS LONG
              DO
              IF g_beepitc=2 THEN EXIT DO
              IF g_beepitsignal THEN
                 IF g_beepitc=1 THEN
                      WinBeep 200,1
                      WinBeep 2700,1
                      WinBeep 5700,1
                   g_beepitsignal=0
                  END IF
              END IF
              SLEEP 1
              LOOP
              
              END FUNCTION
              
              
              THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
              LOCAL IRESULT AS LONG
              LOCAL  i AS LONG
              LOCAL lupdown AS LONG
              LOCAL stimeupdown AS STRING
              lupdown=-1
              stimeupdown=""
              startloop:
              FOR i=1 TO g_iicmplocations
              IRESULT=Pinglocation(g_slocation(i))
              IF iresult THEN EXIT FOR
              IF g_itimeout THEN SLEEP g_itimeout
              NEXT i
              INCR g_iloopsmade
              
              IF iresult THEN
                  INCR g_iicmpmade
                   IF lupdown<>1 THEN
                    IF g_beepit THEN g_beepitsignal=2
                    stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
                    CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                    CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" UP "+stimeupdown
                    DIALOG SET TEXT g_hDlg, UCASE$(g_slocationstring)+" UP"
                    UPDATEWINDOW g_hDlg
                    g_smessagetext2+=DATE$+" "+TIME$+" status is UP"+$CRLF
                    END IF
                 ELSE
                   IF g_beepitc THEN g_beepitsignal=1
                   IF lupdown<>0 THEN
                   IF g_beepit=1 THEN g_beepitsignal=1
                   stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
                   CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
                   CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" down "+stimeupdown
                   DIALOG SET TEXT g_hDlg, LCASE$(g_slocationstring)+" down "
                   UPDATEWINDOW g_hDlg
                   g_smessagetext2+="--------------------------------------------"+$CRLF+DATE$+" "+TIME$+" status is down"+$CRLF
                   END IF
              END IF
              IF g_iloopdelay THEN SLEEP g_iloopdelay
              GOTO startloop
              END FUNCTION
              
              FUNCTION sendtoclipboard() AS LONG
                  LOCAL sTEMP AS STRING
                  DO
                  CLIPBOARD RESET
                  CLIPBOARD GET TEXT STEMP
                  IF LEN(STEMP)=0 THEN EXIT LOOP
                  LOOP
                  CLIPBOARD SET  TEXT g_smessagetext1+g_smessagetext2+g_smessagetext3
              END FUNCTION
              
              
              CALLBACK FUNCTION ShowDIALOG1Proc()
              LOCAL itoclipboard AS LONG
              
              SELECT CASE AS LONG CBMSG
               CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
               CASE %WM_SYSCOMMAND
                           IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                            LOCAL Res AS LONG
                            LOCAL itempbeepit1 AS LONG
                            LOCAL itempbeepit2 AS LONG
                            itempbeepit1=g_beepit:g_beepit=0
                            itempbeepit2=g_beepitc:g_beepitc=0
              
                            Res = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 OR  %MB_ICONMASK , "ICMP monitoring program")
                              IF Res = %IDYES THEN
                                  g_beepit=2 'shutdown the beepit thread
                                  g_beepitc=2 'shutdown the beepitc thread
                                  SLEEP 2000  'allow time for beeping threads to shutdown
                               DIALOG END CB.HNDL
                                ELSE
                                g_beepit=itempbeepit1
                                g_beepitc=itempbeepit2
                                FUNCTION = 1
                               EXIT FUNCTION
                              END IF
                            END IF
               CASE  %WM_COMMAND
                   IF CB.CTL =  %IDC_LABEL1 AND CB.CTLMSG = %STN_Clicked THEN
                        g_smessagetext3="======================"+$CRLF+DATE$+" "+TIME$+" Log report end"+$CRLF+$CRLF
                        g_smessagetext3+="Loops made trying     ="+STR$(g_iloopsmade)+$CRLF
                        g_smessagetext3+="Loops with repsonses  ="+STR$(g_iicmpmade)+$CRLF
                        g_smessagetext3+="Loops with failures   ="+STR$(g_iloopsmade-g_iicmpmade)+$CRLF
                        itoclipboard=MSGBOX(g_smessagetext0+g_smessagetext1+g_smessagetext2+g_smessagetext3+$CRLF+$CRLF+_
                           "Any button closes this log report."+$CRLF+_
                           "Send this ICMP log report to the clipboard?",%MB_OKCANCEL OR  %MB_DEFBUTTON1 OR  %MB_ICONMASK,_
                           "ICMP monitoring program log report")
                        IF itoclipboard=%IDOK  THEN sendtoclipboard
                   END IF
              
               END SELECT
              
              END FUNCTION
              
              
              
              FUNCTION PBMAIN()
                 processstartup
                 IF g_iicmplocations=0 THEN EXIT FUNCTION
                 IF g_beepitc=1 THEN g_beepit=3
                 ShowDIALOG1 %HWND_DESKTOP
              END FUNCTION
              
              
              
              FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                  LOCAL lRslt  AS LONG
                '  LOCAL ghDlg   AS DWORD
                  LOCAL hFont1 AS DWORD
                  LOCAL counter AS LONG
                  LOCAL hthread1 AS DWORD
                  LOCAL hthread2 AS DWORD
                  LOCAL hthread3 AS DWORD
                  LOCAL lresult AS LONG
                  LOCAL lwidth AS LONG
                  lwidth=82
                  IF LEN(COMMAND$(2))=0 THEN
                      lwidth=LEN(g_slocation(1))
                      IF lwidth THEN lwidth=lwidth*8
                      IF lwidth<82 THEN lwidth=82
                      IF lwidth>676 THEN lwidth=676
                  END IF
                  lwidth=lwidth+28
              
                  DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
                      OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
                      OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                      %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                      %WS_EX_RIGHTSCROLLBAR, TO g_hDlg
                  CONTROL ADD LABEL, g_hDlg, %IDC_LABEL1, " Starting ver 1.04", 0, 0, 670, 12, _
                     %SS_NOTIFY OR  %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
                      %WS_EX_LTRREADING
              
                  FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
                  CONTROL SET FONT g_hDlg, %IDC_LABEL1, hFont1
                  IF g_beepit=1 THEN
                  THREAD CREATE beepit(1&) TO hThread2
                  DO WHILE hthread2 = 0
                   SLEEP 150
                  LOOP
                  END IF
                  IF g_beepitc=1 THEN
                  THREAD CREATE beepitc(1&) TO hThread3
                  DO WHILE hthread3 = 0
                   SLEEP 150
                  LOOP
                  END IF
              
                  THREAD CREATE pingtest(1&) TO hThread1
                  DO WHILE hthread1 = 0
                   SLEEP 150
                  LOOP
              
                    DIALOG SHOW MODAL g_hDlg  , CALL ShowDIALOG1Proc TO lRslt
                  FONT END hFont1
                  FUNCTION = lRslt
              
              END FUNCTION
              
              FUNCTION processstartup() AS LONG
              DIM i AS LONG
              DIM j AS LONG
              DIM stemp1 AS STRING
              DIM stemp2 AS STRING
              g_itdelay=0
              g_itimeout=300
              g_iloopdelay=3000
              g_ispaceingoficmp=0
              g_iicmplocations=1000
              
              DIM g_slocation(0 TO g_iicmplocations) AS STRING
              i=0
              DO
              INCR i
              stemp2=LCASE$(TRIM$(COMMAND$(i)))
              IF LEN(stemp2)=0 THEN EXIT DO
              IF stemp2="-d" THEN stemp1=stemp2:ITERATE
              IF stemp2="-t" THEN stemp1=stemp2:ITERATE
              IF stemp2="-s" THEN stemp1=stemp2:ITERATE
              IF stemp2="-l" THEN stemp1=stemp2:ITERATE
              IF stemp2="-v" THEN stemp1=stemp2:ITERATE
              IF stemp2="-b" THEN stemp1="":g_beepit=1:ITERATE
              IF stemp2="-bc" THEN stemp1="":g_beepitc=1:ITERATE
              
              IF STEMP1="-d" THEN g_itdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
              IF STEMP1="-t" THEN g_itimeout=ABS(VAL(stemp2)):stemp1="":ITERATE
              IF STEMP1="-s" THEN g_ispaceingoficmp=ABS(VAL(stemp2)):stemp1="":ITERATE
              IF STEMP1="-l" THEN g_iloopdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
              IF STEMP1="-v" THEN g_itextchange=1:g_stextchange=COMMAND$(i):stemp1="":ITERATE
              INCR j
              g_slocation(j)=stemp2
              stemp1=""
              IF J=1000 THEN EXIT DO
              LOOP
              g_iicmplocations=J
                IF g_iicmplocations=0 THEN
                    MSGBOX "You must place url locations or ip addresses to ping(ICMP) on the command tail."+$CRLF+_
                           "To test a site for multiple sequential ping tries, repeat the location x times."+$CRLF+_
                           "The first location to respond to a ping means a ping response(connection) was made."+$CRLF+$CRLF+_
                           "It is more efficient to use ip address numbers, because url's have to do dns lookups."+$CRLF+_
                           "Other command tail options can change the timing in the ping function and sound alarms."+$CRLF+_
                           " -d xxxxx millisecond delay before the program starts monitoring sites, default 0"+$CRLF+_
                           " -t xxxxx millisecond timeout for a single ping try at each site, default  300"+$CRLF+_
                           " -s xxxxx millisecond delay of time before pinging each site after the first site, default 0"+$CRLF+_
                           " -l xxxxx millisecond delay in loop time before trying the pooled sites again, default 3000"+$CRLF+_
                           "Be careful when using time setting, this program does not check for bad numbers used."+$CRLF+_
                           "1000 milliseconds equals 1 second. Use the ping command to test a site for reasonable response times."+$CRLF+_
                           "Audible alarms, use either -b (up/down changes) or -bc (constant down connections)"+$CRLF+_
                           "Text in the status can be changed by using -v followed by text with no spaces.", %MB_OK OR %MB_ICONMASK,"ICMP Monitoring program"
              
                    EXIT FUNCTION
                 END IF
              
                g_smessagetext0= "If you cannot see the bottom, press enter to send the report to clipboard."+$CRLF
                g_smessagetext0+="or you can close the window with the X button at the top right."+$CRLF
              
                g_smessagetext1+="The program with the command line/tail used to create this log."+$CRLF+EXE.FULL$+" "+COMMAND$+$CRLF
                g_smessagetext1+="Site locations and order used in the pool for ICMP monitoring program."+$CRLF
              
                 FOR i=1 TO g_iicmplocations
                   g_smessagetext1+=TRIM$(STR$(i))+". "+g_slocation(i)+$CRLF
                   IF g_slocation(i)<>g_slocation(1) THEN g_slocationstring="Internet"
                 NEXT i
                 IF g_itextchange=1 AND g_stextchange<>"" THEN g_slocationstring=g_stextchange
                 IF g_slocationstring="" THEN g_slocationstring=g_slocation(1)
              
                 g_smessagetext1+="The first response of an ICMP packet in the pool creates a UP status"+$CRLF
                 g_smessagetext1+="delay before the program starts ICMP monitoring = "+STR$(g_itdelay)+" milliseconds"+$CRLF
                 g_smessagetext1+="timeout used for each ICMP packet sent  = "+STR$(g_itimeout)+" milliseconds"+$CRLF
                 g_smessagetext1+="time of spaceing between each ping test  = "+STR$(g_ispaceingoficmp)+" milliseconds"+$CRLF
                 g_smessagetext1+="loop delay between ICMP testing  = "+STR$(g_iloopdelay)+" milliseconds "+$CRLF
                 g_smessagetext2+=$CRLF+g_slocationstring+" is the text used in the gui status bar"+$CRLF
                 g_smessagetext2+=DATE$+" "+TIME$+" Program start time"+$CRLF
                 IF g_itdelay>0 THEN SLEEP g_itdelay
              
                 g_smessagetext2+=DATE$+" "+TIME$+" Log report start"+$CRLF+"======================"+$CRLF
              
              END FUNCTION
              Attached Files
              Last edited by Paul Purvis; 30 Mar 2012, 10:01 PM.
              p purvis

              Comment


              • #8
                Hi,

                with PowerBasic 10 there is a error here
                Code:
                PE ICMP_ECHO_REPLY
                    Address         AS LONG
                    lStatus          AS LONG    <== Mismatch with prior definition
                                                             Line 42:     lStatus          AS LONG
                Regards,
                Hubert

                ------------------------------------
                http://familie-brandel.de/index_e.html

                Comment


                • #9
                  No, there is a mismatch in your choice of header files and/or options therein and/or your own redefinition of the TYPE and/or other use of the symbol 'ICMP_ECHO_REPLY.'

                  The compiler is obviously working fine, as it caught your error at compile time.
                  Michael Mattias
                  Tal Systems Inc.
                  Racine WI USA
                  mmattias@talsystems.com
                  http://www.talsystems.com

                  Comment


                  • #10
                    Well, i hope i am not opening a BIG can of worms, I probably am.

                    I have been too busy to track down differences in pbwin90 and and pbwin10 in the programs i use, but i was able to compile the program above with pbwin10 using the WIN32API.INC from PBwin9.05

                    It appears that i will be able to sneak the new PLAY statement with the new compiler PBwin version 10 that Stuart McLachlan show us

                    http://www.powerbasic.com/support/pb...ad.php?t=50007
                    p purvis

                    Comment


                    • #11
                      I tried the program with the following commandline

                      internet.exe 10.1.1.50 -t 50 -d 0 -s 0 -bc -v www.yahoo.com

                      Where 10.1.1.50 is our local firewall device which responds to ping.

                      The program reports up. When I disable the Local Area Network Connection to simulate a network disconnect the program continues to report UP.

                      After re-enabling the Local Area Connection, I unplugged the patch cable from the PC it shows DOWN, when plug it back in it shows UP. That works the way I would expect.

                      Is there some other test that needs to be added to ensure a good Local Area Connection?

                      If I change the DNS Settings on the Local Area Connection to bad DNS ip addresses to simulate a DNS failure the program keeps reporting UP. WHen I launch a browser I get problem loading page.

                      Not sure why these two scenarios do not cause the prorgam to report DOWN?

                      Comment


                      • #12
                        Originally posted by Michael Mattias View Post
                        No, there is a mismatch in your choice of header files and/or options therein and/or your own redefinition of the TYPE and/or other use of the symbol 'ICMP_ECHO_REPLY.'
                        The compiler is obviously working fine, as it caught your error at compile time.
                        I know that the compiler reports a double definition and thats a quite good job, because I don't have to read all ;-)
                        But I thought the author of this program is maybe interested to hear that PBWin 10 does report an error in that line :coffee4:
                        Regards,
                        Hubert

                        ------------------------------------
                        http://familie-brandel.de/index_e.html

                        Comment


                        • #13
                          Originally posted by Douglas Martin View Post
                          Not sure why these two scenarios do not cause the prorgam to report DOWN?
                          I tried to test if my webserver is up with a program that loads the webpage with a http request. The first call needs several seconds and does report it right (mostly ON), but all other calls just reports ON out of the cache ...
                          Regards,
                          Hubert

                          ------------------------------------
                          http://familie-brandel.de/index_e.html

                          Comment


                          • #14
                            Douglas
                            I used the same two methods of breaking my internet connection. Yanking the cord was first followed by diabling the interface and the program worked fine on all machines tested. I do not have a windows 7 machine to teet on.
                            I list my dns server as the first two ip addresses to ping. If the dns does return a ping. You just use the same ipaddress about 5 times to see if it is up or down
                            This program does need about 4 and best 5 ipaddresses to cause a good reliable factor to determine failure. If the timeouts are short and loops are short. You might as well set more than 5 ipaddresses in the pool.

                            Concerning dns failures. I have not test that and i think dns cache was mentioned that might keep you green if the site it is accessing is up and responding to pings.

                            I did have a some problems with our isp dns servers being down. Since then i know use googles dns servers 8.8.8.8 for the secondary dns in our routers and computers and with the isp's second dns server, i place it third in the computer.
                            I feel your green status on checking must be cache. Try CCleaner and let it erase the cache.

                            By the way, i started to cache any url's ipaddresses given to the program to speed up the program but decided against it because the user can put only ipaddesses in the pool if that is what they need for speed.
                            My last version even suggest that to the user.
                            p purvis

                            Comment


                            • #15
                              I have looked at the changes in pbwin10 and played with it for about 4 hours.
                              No success yet but i have started seeing other older post that most likely will prove beneficial to correcting the issues.
                              I might use the wrong words now to describe what i am seeing so until i get work through that, i need to be quiet.
                              But i will say a shift from wsocks to w2_32 does not seem to be any benefits in this program. And from what i read on the internet, w2_32 is not supported on old os systems. Maybe w2_32 is more stable or quicker. I do not know. I do know it supports IPv6 bit internet functions.
                              Last edited by Paul Purvis; 5 Apr 2012, 06:14 PM.
                              p purvis

                              Comment


                              • #16
                                please see Dave Bigg's post here on pinging with pbwin10
                                http://www.powerbasic.com/support/pb....php?p=403698#

                                i will try his code merged into the internet.bas source code.

                                a short test seem to get things going with one exception that i am not clear on as yet
                                and that is in using the icmp.dll file or using the Iphlpapi.dll file for icmp functions
                                p purvis

                                Comment


                                • #17
                                  in the program below, if you replace icmp.dll with Iphlpapi.dll in the declare functions then you can only run this program with xp or better
                                  i am using icmp.dll with this program


                                  after working with the code to make it pbwin10 compatible, i went ahead and used of Dave Biggs code with some slight adjustments.
                                  thanks Dave for responding to Russ Scole's post with a way to ping, see the above posting for a link

                                  i also want to mention that if i read right on the internet, 1000 milliseconds is standard timeout period for pinging although this program has a default timeout much lower
                                  unless you changed it in the command tail, but even though i have shortened it in practice, i cannot actually get the icmpsendecho to timeout when i think it should timeout.


                                  Code:
                                  'Internet.bas
                                  'program pings sites to see if the internet is up or down using ICMP
                                  'compiled with pbwin 10.03
                                  #COMPILE EXE
                                  #DIM ALL
                                  #INCLUDE ONCE "WIN32API.INC"
                                  GLOBAL g_hDlg   AS DWORD
                                  GLOBAL g_slocation() AS STRING
                                  GLOBAL g_slocationstring AS STRING
                                  GLOBAL g_smessagetext0 AS STRING ' message goes on the top of the log report in the msgbox
                                  GLOBAL g_smessagetext1 AS STRING ' holds the log report header plus the locations pinged
                                  GLOBAL g_smessagetext2 AS STRING ' holds the log on pinging locations being up or down as a group
                                  GLOBAL g_smessagetext3 AS STRING ' holds the log report ending
                                  
                                  GLOBAL g_itimeout AS LONG
                                  GLOBAL g_iloopdelay AS LONG
                                  GLOBAL g_itdelay AS LONG
                                  GLOBAL g_ispaceingoficmp AS LONG
                                  GLOBAL g_iicmplocations  AS LONG
                                  GLOBAL g_iicmpmade AS QUAD
                                  GLOBAL g_iloopsmade AS QUAD
                                  GLOBAL g_beepit AS LONG
                                  GLOBAL g_beepitc AS LONG
                                  GLOBAL g_beepitsignal AS LONG
                                  GLOBAL g_itextchange AS LONG
                                  GLOBAL g_stextchange AS STRING
                                  
                                  
                                  
                                  '%IDD_DIALOG1  =  101
                                  %IDC_LABEL1   = 1001
                                  
                                  DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile" () AS DWORD
                                  DECLARE FUNCTION IcmpSendEcho   LIB "icmp.dll" ALIAS "IcmpSendEcho" ( _
                                      BYVAL IcmpHandle         AS DWORD, _
                                      BYVAL DestinationAddress AS DWORD, _
                                      RequestData              AS ANY, _
                                      BYVAL RequestSize        AS WORD, _
                                      RequestOptions           AS IP_OPTION_INFORMATION, _
                                      ReplyBuffer              AS ANY, _
                                      BYVAL ReplySize          AS DWORD, _
                                      BYVAL Timeout            AS DWORD _
                                      ) AS DWORD
                                  DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS DWORD) AS LONG
                                  
                                  FUNCTION PingIpAddress(BYVAL sHost AS STRING) AS LONG
                                    LOCAL hPort AS DWORD, dwAddress AS DWORD,iret AS DWORD
                                    LOCAL ECHO AS ICMP_ECHO_REPLY
                                    LOCAL sRqData AS STRING
                                    FUNCTION = 0
                                    IF LEN(TRIM$(shost))=0 THEN EXIT FUNCTION
                                    HOST ADDR sHost TO dwAddress
                                    IF dwAddress= 165795656 THEN EXIT FUNCTION ' not good
                                        hPort = IcmpCreateFile()
                                     IF hPort = 0 THEN EXIT FUNCTION ' not good
                                  
                                     sRqData = "abcdefghijklmnop" '"Playback"
                                     iret = IcmpSendEcho( _
                                               hPort, _
                                               dwAddress, _
                                               sRqData, _
                                               LEN(sRqData), _
                                               BYVAL 0, _
                                               ECHO, _
                                               LEN(ECHO)+LEN(sRqData), _       ' < NB buffer size plus len of "Request Data"
                                               BYVAL 0) 'g_itimeout)                     ' use 1000. ret = 11010 (IP_REQ_TIMED_OUT) if 100ms
                                  
                                     CALL IcmpCloseHandle(hPort)
                                               ' if echo.status it's not zero then it didn't ping
                                     IF echo.status=0 THEN FUNCTION=1   'success
                                  END FUNCTION
                                  
                                  
                                  'DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                                  DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                  
                                  
                                  THREAD FUNCTION beepit(BYVAL x AS LONG) AS LONG
                                  DO
                                  IF g_beepit=2 THEN EXIT DO
                                  IF g_beepitsignal THEN
                                      IF g_beepit=1 THEN
                                          IF g_beepitsignal=2 THEN WinBeep 5000,50
                                          IF g_beepitsignal=1 THEN WinBeep 100,50
                                          g_beepitsignal=0
                                      END IF
                                  END IF
                                  SLEEP 1
                                  
                                  
                                  LOOP
                                  END FUNCTION
                                  
                                  THREAD FUNCTION beepitc(BYVAL x AS LONG) AS LONG
                                  DO
                                  IF g_beepitc=2 THEN EXIT DO
                                  IF g_beepitsignal THEN
                                     IF g_beepitc=1 THEN
                                          WinBeep 200,1
                                          WinBeep 2700,1
                                          WinBeep 5700,1
                                       g_beepitsignal=0
                                      END IF
                                  END IF
                                  SLEEP 1
                                  LOOP
                                  
                                  END FUNCTION
                                  
                                  
                                  THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
                                  LOCAL IRESULT AS LONG
                                  LOCAL  i AS LONG
                                  LOCAL lupdown AS LONG
                                  LOCAL stimeupdown AS STRING
                                  lupdown=-1
                                  stimeupdown=""
                                  startloop:
                                  FOR i=1 TO g_iicmplocations
                                  IRESULT=pingipaddress(g_slocation(i))
                                  
                                  IF iresult THEN EXIT FOR
                                  IF g_itimeout THEN SLEEP g_itimeout
                                  NEXT i
                                  INCR g_iloopsmade
                                  
                                  IF iresult THEN
                                      INCR g_iicmpmade
                                       IF lupdown<>1 THEN
                                        IF g_beepit THEN g_beepitsignal=2
                                        stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
                                        CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                                        CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" UP "+stimeupdown
                                        DIALOG SET TEXT g_hDlg, UCASE$(g_slocationstring)+" UP"
                                        UPDATEWINDOW g_hDlg
                                        g_smessagetext2+=DATE$+" "+TIME$+" status is UP"+$CRLF
                                        END IF
                                     ELSE
                                       IF g_beepitc THEN g_beepitsignal=1
                                       IF lupdown<>0 THEN
                                       IF g_beepit=1 THEN g_beepitsignal=1
                                       stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
                                       CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
                                       CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" down "+stimeupdown
                                       DIALOG SET TEXT g_hDlg, LCASE$(g_slocationstring)+" down "
                                       UPDATEWINDOW g_hDlg
                                       g_smessagetext2+="--------------------------------------------"+$CRLF+DATE$+" "+TIME$+" status is down"+$CRLF
                                       END IF
                                  END IF
                                  IF g_iloopdelay THEN SLEEP g_iloopdelay
                                  GOTO startloop
                                  END FUNCTION
                                  
                                  FUNCTION sendtoclipboard() AS LONG
                                      LOCAL sTEMP AS STRING
                                      DO
                                      CLIPBOARD RESET
                                      CLIPBOARD GET TEXT STEMP
                                      IF LEN(STEMP)=0 THEN EXIT LOOP
                                      LOOP
                                      CLIPBOARD SET  TEXT g_smessagetext1+g_smessagetext2+g_smessagetext3
                                  END FUNCTION
                                  
                                  
                                  CALLBACK FUNCTION ShowDIALOG1Proc()
                                  LOCAL itoclipboard AS LONG
                                  
                                  SELECT CASE AS LONG CBMSG
                                   CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
                                   CASE %WM_SYSCOMMAND
                                               IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                                                LOCAL RES AS LONG
                                                LOCAL itempbeepit1 AS LONG
                                                LOCAL itempbeepit2 AS LONG
                                                itempbeepit1=g_beepit:g_beepit=0
                                                itempbeepit2=g_beepitc:g_beepitc=0
                                  
                                                RES = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 OR  %MB_ICONMASK , "ICMP monitoring program")
                                                  IF RES = %IDYES THEN
                                                      g_beepit=2 'shutdown the beepit thread
                                                      g_beepitc=2 'shutdown the beepitc thread
                                                      SLEEP 2000  'allow time for beeping threads to shutdown
                                                   DIALOG END CB.HNDL
                                                    ELSE
                                                    g_beepit=itempbeepit1
                                                    g_beepitc=itempbeepit2
                                                    FUNCTION = 1
                                                   EXIT FUNCTION
                                                  END IF
                                                END IF
                                   CASE  %WM_COMMAND
                                       IF CB.CTL =  %IDC_LABEL1 AND CB.CTLMSG = %STN_Clicked THEN
                                            g_smessagetext3="======================"+$CRLF+DATE$+" "+TIME$+" Log report end"+$CRLF+$CRLF
                                            g_smessagetext3+="Loops made trying     ="+STR$(g_iloopsmade)+$CRLF
                                            g_smessagetext3+="Loops with repsonses  ="+STR$(g_iicmpmade)+$CRLF
                                            g_smessagetext3+="Loops with failures   ="+STR$(g_iloopsmade-g_iicmpmade)+$CRLF
                                            itoclipboard=MSGBOX(g_smessagetext0+g_smessagetext1+g_smessagetext2+g_smessagetext3+$CRLF+$CRLF+_
                                               "Any button closes this log report."+$CRLF+_
                                               "Send this ICMP log report to the clipboard?",%MB_OKCANCEL OR  %MB_DEFBUTTON1 OR  %MB_ICONMASK,_
                                               "ICMP monitoring program log report")
                                            IF itoclipboard=%IDOK  THEN sendtoclipboard
                                       END IF
                                  
                                   END SELECT
                                  
                                  END FUNCTION
                                  
                                  
                                  
                                  FUNCTION PBMAIN()
                                     processstartup
                                     IF g_iicmplocations=0 THEN EXIT FUNCTION
                                     IF g_beepitc=1 THEN g_beepit=3
                                     ShowDIALOG1 %HWND_DESKTOP
                                  END FUNCTION
                                  
                                  
                                  
                                  FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                      LOCAL lRslt  AS LONG
                                    '  LOCAL ghDlg   AS DWORD
                                      LOCAL hFont1 AS DWORD
                                      LOCAL counter AS LONG
                                      LOCAL hthread1 AS DWORD
                                      LOCAL hthread2 AS DWORD
                                      LOCAL hthread3 AS DWORD
                                      LOCAL lresult AS LONG
                                      LOCAL lwidth AS LONG
                                      lwidth=82
                                      IF LEN(COMMAND$(2))=0 THEN
                                          lwidth=LEN(g_slocation(1))
                                          IF lwidth THEN lwidth=lwidth*8
                                          IF lwidth<82 THEN lwidth=82
                                          IF lwidth>676 THEN lwidth=676
                                      END IF
                                      lwidth=lwidth+28
                                  
                                      DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
                                          OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
                                          OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                                          %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                          %WS_EX_RIGHTSCROLLBAR, TO g_hDlg
                                      CONTROL ADD LABEL, g_hDlg, %IDC_LABEL1, " Starting ver 1.05", 0, 0, 670, 12, _
                                         %SS_NOTIFY OR  %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING
                                  
                                      FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
                                      CONTROL SET FONT g_hDlg, %IDC_LABEL1, hFont1
                                      IF g_beepit=1 THEN
                                      THREAD CREATE beepit(1&) TO hThread2
                                      DO WHILE hthread2 = 0
                                       SLEEP 150
                                      LOOP
                                      END IF
                                      IF g_beepitc=1 THEN
                                      THREAD CREATE beepitc(1&) TO hThread3
                                      DO WHILE hthread3 = 0
                                       SLEEP 150
                                      LOOP
                                      END IF
                                  
                                      THREAD CREATE pingtest(1&) TO hThread1
                                      DO WHILE hthread1 = 0
                                       SLEEP 150
                                      LOOP
                                  
                                        DIALOG SHOW MODAL g_hDlg  , CALL ShowDIALOG1Proc TO lRslt
                                      FONT END hFont1
                                      FUNCTION = lRslt
                                  
                                  END FUNCTION
                                  
                                  FUNCTION processstartup() AS LONG
                                  DIM i AS LONG
                                  DIM j AS LONG
                                  DIM stemp1 AS STRING
                                  DIM stemp2 AS STRING
                                  g_itdelay=0
                                  g_itimeout=300
                                  g_iloopdelay=3000
                                  g_ispaceingoficmp=0
                                  g_iicmplocations=1000
                                  
                                  DIM g_slocation(0 TO g_iicmplocations) AS STRING
                                  i=0
                                  DO
                                  INCR i
                                  stemp2=LCASE$(TRIM$(COMMAND$(i)))
                                  IF LEN(stemp2)=0 THEN EXIT DO
                                  IF stemp2="-d" THEN stemp1=stemp2:ITERATE
                                  IF stemp2="-t" THEN stemp1=stemp2:ITERATE
                                  IF stemp2="-s" THEN stemp1=stemp2:ITERATE
                                  IF stemp2="-l" THEN stemp1=stemp2:ITERATE
                                  IF stemp2="-v" THEN stemp1=stemp2:ITERATE
                                  IF stemp2="-b" THEN stemp1="":g_beepit=1:ITERATE
                                  IF stemp2="-bc" THEN stemp1="":g_beepitc=1:ITERATE
                                  
                                  IF STEMP1="-d" THEN g_itdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
                                  IF STEMP1="-t" THEN g_itimeout=ABS(VAL(stemp2)):stemp1="":ITERATE
                                  IF STEMP1="-s" THEN g_ispaceingoficmp=ABS(VAL(stemp2)):stemp1="":ITERATE
                                  IF STEMP1="-l" THEN g_iloopdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
                                  IF STEMP1="-v" THEN g_itextchange=1:g_stextchange=COMMAND$(i):stemp1="":ITERATE
                                  INCR j
                                  g_slocation(j)=stemp2
                                  stemp1=""
                                  IF J=1000 THEN EXIT DO
                                  LOOP
                                  g_iicmplocations=J
                                    IF g_iicmplocations=0 THEN
                                        MSGBOX "You must place url locations or ip addresses to ping(ICMP) on the command tail."+$CRLF+_
                                               "To test a site for multiple sequential ping tries, repeat the location x times."+$CRLF+_
                                               "The first location to respond to a ping means a ping response(connection) was made."+$CRLF+$CRLF+_
                                               "It is more efficient to use ip address numbers, because url's have to do dns lookups."+$CRLF+_
                                               "Other command tail options can change the timing in the ping function and sound alarms."+$CRLF+_
                                               " -d xxxxx millisecond delay before the program starts monitoring sites, default 0"+$CRLF+_
                                               " -t xxxxx millisecond timeout for a single ping try at each site, default  300"+$CRLF+_
                                               " -s xxxxx millisecond delay of time before pinging each site after the first site, default 0"+$CRLF+_
                                               " -l xxxxx millisecond delay in loop time before trying the pooled sites again, default 3000"+$CRLF+_
                                               "Be careful when using time setting, this program does not check for bad numbers used."+$CRLF+_
                                               "1000 milliseconds equals 1 second. Use the ping command to test a site for reasonable response times."+$CRLF+_
                                               "Audible alarms, use either -b (up/down changes) or -bc (constant down connections)"+$CRLF+_
                                               "Text in the status can be changed by using -v followed by text with no spaces.", %MB_OK OR %MB_ICONMASK,"ICMP Monitoring program"
                                  
                                        EXIT FUNCTION
                                     END IF
                                  
                                    g_smessagetext0= "If you cannot see the bottom, press enter to send the report to clipboard."+$CRLF
                                    g_smessagetext0+="or you can close the window with the X button at the top right."+$CRLF
                                  
                                    g_smessagetext1+="The program with the command line/tail used to create this log."+$CRLF+EXE.FULL$+" "+COMMAND$+$CRLF
                                    g_smessagetext1+="Site locations and order used in the pool for ICMP monitoring program."+$CRLF
                                  
                                     FOR i=1 TO g_iicmplocations
                                       g_smessagetext1+=TRIM$(STR$(i))+". "+g_slocation(i)+$CRLF
                                       IF g_slocation(i)<>g_slocation(1) THEN g_slocationstring="Internet"
                                     NEXT i
                                     IF g_itextchange=1 AND g_stextchange<>"" THEN g_slocationstring=g_stextchange
                                     IF g_slocationstring="" THEN g_slocationstring=g_slocation(1)
                                  
                                     g_smessagetext1+="The first response of an ICMP packet in the pool creates a UP status"+$CRLF
                                     g_smessagetext1+="delay before the program starts ICMP monitoring = "+STR$(g_itdelay)+" milliseconds"+$CRLF
                                     g_smessagetext1+="timeout used for each ICMP packet sent  = "+STR$(g_itimeout)+" milliseconds"+$CRLF
                                     g_smessagetext1+="time of spaceing between each ping test  = "+STR$(g_ispaceingoficmp)+" milliseconds"+$CRLF
                                     g_smessagetext1+="loop delay between ICMP testing  = "+STR$(g_iloopdelay)+" milliseconds "+$CRLF
                                     g_smessagetext2+=$CRLF+g_slocationstring+" is the text used in the gui status bar"+$CRLF
                                     g_smessagetext2+=DATE$+" "+TIME$+" Program start time"+$CRLF
                                     IF g_itdelay>0 THEN SLEEP g_itdelay
                                  
                                     g_smessagetext2+=DATE$+" "+TIME$+" Log report start"+$CRLF+"======================"+$CRLF
                                  
                                  END FUNCTION
                                  Attached Files
                                  Last edited by Paul Purvis; 5 Apr 2012, 08:39 PM.
                                  p purvis

                                  Comment


                                  • #18
                                    Douglas
                                    i did your test after a rewrite in pbwin10 source, no sense in doing test with the old, right?

                                    i tested your conditions on my computer, a windows 2000 pro
                                    in your test change www.yahoo.com to firewall
                                    the www.yahoo.com is an unbroken text that becomes the text in the box

                                    internet.exe 10.1.1.50 -t 50 -d 0 -s 0 -bc -v firewall
                                    also because this is a lan connection, you might not lose any ping responses, the ones you will get will be fast, but you might do this
                                    internet.exe 10.1.1.50 10.1.1.50 10.1.1.50 -t 50 -d 0 -s 0 -bc -v firewall

                                    i had no issues, all worked as expected
                                    if you have issues, please let me know
                                    p purvis

                                    Comment


                                    • #19
                                      a new improved version
                                      made some minor changes to improve the progam
                                      added a yellow light option
                                      the new option command tail is -yellowlight after a single location to ping
                                      so if you want a yellow light ofter the faiilure to ping the second location
                                      you can use the command:
                                      internet a.a.a.a b.b.b.b -yellowlight c.c.c.c d.d.d.d
                                      or
                                      internet a.a.a.a a.a.a.a -yellowlight b.b.b.b c.c.c.c

                                      the yellow light might help to see ping response failures if you are having to troubleshoot connection issues

                                      Code:
                                      'Internet.bas
                                      'program pings sites to see if the internet is up or down using ICMP
                                      'compiled with pbwin 10.03
                                      #COMPILE EXE
                                      #DIM ALL
                                      #INCLUDE ONCE "WIN32API.INC"
                                      GLOBAL g_hDlg   AS DWORD
                                      GLOBAL g_slocation() AS STRING
                                      GLOBAL g_slocationstring AS STRING
                                      GLOBAL g_smessagetext0 AS STRING ' message goes on the top of the log report in the msgbox
                                      GLOBAL g_smessagetext1 AS STRING ' holds the log report header plus the locations pinged
                                      GLOBAL g_smessagetext2 AS STRING ' holds the log on pinging locations being up or down as a group
                                      GLOBAL g_smessagetext3 AS STRING ' holds the log report ending
                                      
                                      GLOBAL g_itimeout AS LONG
                                      GLOBAL g_iloopdelay AS LONG
                                      GLOBAL g_itdelay AS LONG
                                      GLOBAL g_ispaceingoficmp AS LONG
                                      GLOBAL g_iicmplocations  AS LONG
                                      GLOBAL g_iicmpmade AS QUAD
                                      GLOBAL g_iloopsmade AS QUAD
                                      GLOBAL g_beepit AS LONG
                                      GLOBAL g_beepitc AS LONG
                                      GLOBAL g_beepitsignal AS LONG
                                      GLOBAL g_itextchange AS LONG
                                      GLOBAL g_stextchange AS STRING
                                      GLOBAL g_shutdown AS LONG
                                      GLOBAL g_yellowlight AS LONG
                                      GLOBAL g_yellowlightstatus AS LONG
                                      
                                      
                                      
                                      '%IDD_DIALOG1  =  101
                                      %IDC_LABEL1   = 1001
                                      
                                      DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile" () AS DWORD
                                      DECLARE FUNCTION IcmpSendEcho   LIB "icmp.dll" ALIAS "IcmpSendEcho" ( _
                                          BYVAL IcmpHandle         AS DWORD, _
                                          BYVAL DestinationAddress AS DWORD, _
                                          RequestData              AS ANY, _
                                          BYVAL RequestSize        AS WORD, _
                                          RequestOptions           AS IP_OPTION_INFORMATION, _
                                          ReplyBuffer              AS ANY, _
                                          BYVAL ReplySize          AS DWORD, _
                                          BYVAL Timeout            AS DWORD _
                                          ) AS DWORD
                                      DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS DWORD) AS LONG
                                      
                                      FUNCTION PingIpAddress(BYVAL sHost AS STRING) AS LONG
                                        LOCAL hPort AS DWORD, dwAddress AS DWORD,iret AS DWORD
                                        LOCAL ECHO AS ICMP_ECHO_REPLY
                                        LOCAL sRqData AS STRING
                                        FUNCTION = 0
                                        IF LEN(TRIM$(shost))=0 THEN EXIT FUNCTION
                                        HOST ADDR sHost TO dwAddress
                                        IF dwAddress= 165795656 THEN EXIT FUNCTION ' not good
                                            hPort = IcmpCreateFile()
                                         IF hPort = 0 THEN EXIT FUNCTION ' not good
                                      
                                         sRqData = "abcdefghijklmnop" '"Playback"
                                         iret = IcmpSendEcho( _
                                                   hPort, _
                                                   dwAddress, _
                                                   sRqData, _
                                                   LEN(sRqData), _
                                                   BYVAL 0, _
                                                   ECHO, _
                                                   LEN(ECHO)+LEN(sRqData), _       ' < NB buffer size plus len of "Request Data"
                                                   BYVAL 0) 'g_itimeout)                     ' use 1000. ret = 11010 (IP_REQ_TIMED_OUT) if 100ms
                                      
                                         CALL IcmpCloseHandle(hPort)
                                                   ' if echo.status it's not zero then it didn't ping
                                         IF echo.status=0 THEN FUNCTION=1   'success
                                      END FUNCTION
                                      
                                      
                                      'DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                                      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                      
                                      
                                      THREAD FUNCTION beepit(BYVAL x AS LONG) AS LONG
                                      DO
                                      IF g_shutdown THEN EXIT DO
                                      IF g_beepitsignal THEN
                                          IF g_beepit=1 THEN
                                              IF g_beepitsignal=2 THEN WinBeep 5000,50
                                              IF g_beepitsignal=1 THEN WinBeep 100,50
                                              g_beepitsignal=0
                                          END IF
                                      END IF
                                      SLEEP 1
                                      LOOP
                                      END FUNCTION
                                      
                                      THREAD FUNCTION beepitc(BYVAL x AS LONG) AS LONG
                                      DO
                                      IF g_shutdown THEN EXIT DO
                                      IF g_beepitsignal THEN
                                         IF g_beepitc=1 THEN
                                              WinBeep 200,1
                                              WinBeep 2700,1
                                              WinBeep 5700,1
                                           g_beepitsignal=0
                                          END IF
                                      END IF
                                      SLEEP 1
                                      LOOP
                                      
                                      END FUNCTION
                                      
                                      
                                      THREAD FUNCTION pingtest(BYVAL x AS LONG) AS LONG
                                      LOCAL IRESULT AS LONG
                                      LOCAL  i AS LONG
                                      LOCAL lupdown AS LONG
                                      LOCAL stimeupdown AS STRING
                                      lupdown=-1
                                      stimeupdown=""
                                      startloop:
                                      IF g_shutdown THEN EXIT FUNCTION
                                      
                                      FOR i=1 TO g_iicmplocations
                                      IRESULT=pingipaddress(g_slocation(i))
                                      IF iresult THEN EXIT FOR
                                      IF g_yellowlight=i THEN
                                          IF lupdown=1 THEN  CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_SANDYBROWN
                                          CONTROL REDRAW g_hDlg, %IDC_LABEL1
                                          g_yellowlightstatus=1
                                      END IF
                                      IF g_itimeout AND i<> g_iicmplocations THEN SLEEP g_itimeout
                                      NEXT i
                                      INCR g_iloopsmade
                                      
                                      IF iresult THEN
                                            INCR g_iicmpmade
                                            IF g_yellowlightstatus=1 THEN
                                                CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                                                CONTROL REDRAW g_hDlg, %IDC_LABEL1
                                                g_yellowlightstatus=0
                                            END IF
                                            IF lupdown<>1 THEN
                                            IF g_beepit THEN g_beepitsignal=2
                                            stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=1
                                            CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_GREEN
                                            CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" UP "+stimeupdown
                                            DIALOG SET TEXT g_hDlg, UCASE$(g_slocationstring)+" UP"
                                            CONTROL REDRAW g_hDlg, %IDC_LABEL1
                                            g_smessagetext2+=DATE$+" "+TIME$+" status is UP"+$CRLF
                                            END IF
                                         ELSE
                                           g_yellowlightstatus=0
                                           IF g_beepitc THEN g_beepitsignal=1
                                           IF lupdown<>0 THEN
                                           IF g_beepit=1 THEN g_beepitsignal=1
                                           stimeupdown=MID$(DATE$,1,5)+" "+TIME$:lupdown=0
                                           CONTROL SET COLOR g_hDlg, %IDC_LABEL1, %RGB_WHITE, %RGB_RED
                                           CONTROL SET TEXT g_hDlg, %IDC_LABEL1, g_slocationstring+" down "+stimeupdown
                                           DIALOG SET TEXT g_hDlg, LCASE$(g_slocationstring)+" down "
                                           CONTROL REDRAW g_hDlg, %IDC_LABEL1
                                           g_smessagetext2+="--------------------------------------------"+$CRLF+DATE$+" "+TIME$+" status is down"+$CRLF
                                           END IF
                                      END IF
                                      IF g_iloopdelay THEN SLEEP g_iloopdelay
                                      GOTO startloop
                                      END FUNCTION
                                      
                                      FUNCTION sendtoclipboard() AS LONG
                                          LOCAL sTEMP AS STRING
                                          DO
                                          CLIPBOARD RESET
                                          CLIPBOARD GET TEXT STEMP
                                          IF LEN(STEMP)=0 THEN EXIT LOOP
                                          LOOP
                                          CLIPBOARD SET  TEXT g_smessagetext1+g_smessagetext2+g_smessagetext3
                                      END FUNCTION
                                      
                                      
                                      CALLBACK FUNCTION ShowDIALOG1Proc()
                                      LOCAL itoclipboard AS LONG
                                      
                                      SELECT CASE AS LONG CBMSG
                                       CASE %WM_INITDIALOG  ' <- Received right before the dialog is shown
                                       CASE %WM_SYSCOMMAND
                                                   IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                                                    LOCAL RES AS LONG
                                      
                                                    RES = MSGBOX ("Really close the program?", %MB_YESNO OR %MB_DEFBUTTON2 OR  %MB_ICONMASK , "ICMP monitoring program")
                                                      IF RES = %IDYES THEN
                                                          g_shutdown=1 'to shutdown threads
                                                          DO
                                                            SLEEP 0
                                                          LOOP WHILE THREADCOUNT > 1
                                                          DIALOG END CB.HNDL
                                                        ELSE
                                                          FUNCTION = 1
                                                       EXIT FUNCTION
                                                      END IF
                                                    END IF
                                       CASE  %WM_COMMAND
                                           IF CB.CTL =  %IDC_LABEL1 AND CB.CTLMSG = %STN_Clicked THEN
                                                g_smessagetext3="======================"+$CRLF+DATE$+" "+TIME$+" Log report end"+$CRLF+$CRLF
                                                g_smessagetext3+="Loops made trying     ="+STR$(g_iloopsmade)+$CRLF
                                                g_smessagetext3+="Loops with repsonses  ="+STR$(g_iicmpmade)+$CRLF
                                                g_smessagetext3+="Loops with failures   ="+STR$(g_iloopsmade-g_iicmpmade)+$CRLF
                                                itoclipboard=MSGBOX(g_smessagetext0+g_smessagetext1+g_smessagetext2+g_smessagetext3+$CRLF+$CRLF+_
                                                   "Any button closes this log report."+$CRLF+_
                                                   "Send this ICMP log report to the clipboard?",%MB_OKCANCEL OR  %MB_DEFBUTTON1 OR  %MB_ICONMASK,_
                                                   "ICMP monitoring program log report")
                                                IF itoclipboard=%IDOK  THEN sendtoclipboard
                                           END IF
                                      
                                       END SELECT
                                      
                                      END FUNCTION
                                      
                                      
                                      
                                      FUNCTION PBMAIN()
                                         processstartup
                                         IF g_iicmplocations=0 THEN EXIT FUNCTION
                                         IF g_beepitc=1 THEN g_beepit=0
                                         ShowDIALOG1 %HWND_DESKTOP
                                      END FUNCTION
                                      
                                      
                                      
                                      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                          LOCAL lRslt  AS LONG
                                        '  LOCAL ghDlg   AS DWORD
                                          LOCAL hFont1 AS DWORD
                                          LOCAL counter AS LONG
                                          LOCAL hthread1 AS DWORD
                                          LOCAL hthread2 AS DWORD
                                          LOCAL hthread3 AS DWORD
                                          LOCAL lresult AS LONG
                                          LOCAL lwidth AS LONG
                                          lwidth=82
                                          IF LEN(COMMAND$(2))=0 THEN
                                              lwidth=LEN(g_slocation(1))
                                              IF lwidth THEN lwidth=lwidth*8
                                              IF lwidth<82 THEN lwidth=82
                                              IF lwidth>676 THEN lwidth=676
                                          END IF
                                          lwidth=lwidth+28
                                      
                                          DIALOG NEW hParent, "Internet", 70, 70, lwidth, 9, %WS_POPUP OR %WS_BORDER _
                                              OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX _
                                              OR %WS_VISIBLE OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
                                              %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                                              %WS_EX_RIGHTSCROLLBAR, TO g_hDlg
                                          CONTROL ADD LABEL, g_hDlg, %IDC_LABEL1, " Starting ver 1.06", 0, 0, 670, 12, _
                                             %SS_NOTIFY OR  %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT, %WS_EX_LEFT OR _
                                              %WS_EX_LTRREADING
                                      
                                          FONT NEW "MS Sans Serif", 10, 0, %ANSI_CHARSET TO hFont1
                                          CONTROL SET FONT g_hDlg, %IDC_LABEL1, hFont1
                                          IF g_beepit=1 THEN
                                          THREAD CREATE beepit(1&) TO hThread2
                                          DO WHILE hthread2 = 0
                                           SLEEP 150
                                          LOOP
                                          END IF
                                          IF g_beepitc=1 THEN
                                          THREAD CREATE beepitc(1&) TO hThread3
                                          DO WHILE hthread3 = 0
                                           SLEEP 150
                                          LOOP
                                          END IF
                                      
                                          THREAD CREATE pingtest(1&) TO hThread1
                                          DO WHILE hthread1 = 0
                                           SLEEP 150
                                          LOOP
                                      
                                            DIALOG SHOW MODAL g_hDlg  , CALL ShowDIALOG1Proc TO lRslt
                                          FONT END hFont1
                                          FUNCTION = lRslt
                                      
                                      END FUNCTION
                                      
                                      FUNCTION processstartup() AS LONG
                                      DIM i AS LONG
                                      DIM j AS LONG
                                      DIM stemp1 AS STRING
                                      DIM stemp2 AS STRING
                                      g_itdelay=0
                                      g_itimeout=300
                                      g_iloopdelay=3000
                                      g_ispaceingoficmp=0
                                      g_iicmplocations=1000
                                      
                                      DIM g_slocation(0 TO g_iicmplocations) AS STRING
                                      i=0
                                      DO
                                      INCR i
                                      stemp2=LCASE$(TRIM$(COMMAND$(i)))
                                      IF LEN(stemp2)=0 THEN EXIT DO
                                      IF stemp2="-d" THEN stemp1=stemp2:ITERATE
                                      IF stemp2="-t" THEN stemp1=stemp2:ITERATE
                                      IF stemp2="-s" THEN stemp1=stemp2:ITERATE
                                      IF stemp2="-l" THEN stemp1=stemp2:ITERATE
                                      IF stemp2="-v" THEN stemp1=stemp2:ITERATE
                                      IF stemp2="-b" THEN stemp1="":g_beepit=1:ITERATE
                                      IF stemp2="-bc" THEN stemp1="":g_beepitc=1:ITERATE
                                      
                                      IF stemp2="-yellowlight" THEN stemp1="":g_yellowlight=j:ITERATE
                                      
                                      IF STEMP1="-d" THEN g_itdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
                                      IF STEMP1="-t" THEN g_itimeout=ABS(VAL(stemp2)):stemp1="":ITERATE
                                      IF STEMP1="-s" THEN g_ispaceingoficmp=ABS(VAL(stemp2)):stemp1="":ITERATE
                                      IF STEMP1="-l" THEN g_iloopdelay=ABS(VAL(stemp2)):stemp1="":ITERATE
                                      IF STEMP1="-v" THEN g_itextchange=1:g_stextchange=COMMAND$(i):stemp1="":ITERATE
                                      
                                      INCR j
                                      g_slocation(j)=stemp2
                                      stemp1=""
                                      IF J=1000 THEN EXIT DO
                                      LOOP
                                      g_iicmplocations=J
                                        IF g_iicmplocations=0 THEN
                                            MSGBOX "You must place url locations or ip addresses to ping(ICMP) on the command tail."+$CRLF+_
                                                   "To test a site for multiple sequential ping tries, repeat the location x times."+$CRLF+_
                                                   "The first location to respond to a ping means a ping response(connection) was made."+$CRLF+$CRLF+_
                                                   "It is more efficient to use ip address numbers, because url's have to do dns lookups."+$CRLF+_
                                                   "Other command tail options can change the timing in the ping function and sound alarms."+$CRLF+_
                                                   " -d xxxxx millisecond delay before the program starts monitoring sites, default 0"+$CRLF+_
                                                   " -t xxxxx millisecond timeout for a single ping try at each site, default  300"+$CRLF+_
                                                   " -s xxxxx millisecond delay of time before pinging each site after the first site, default 0"+$CRLF+_
                                                   " -l xxxxx millisecond delay in loop time before trying the pooled sites again, default 3000"+$CRLF+_
                                                   "Be careful when using time setting, this program does not check for bad numbers used."+$CRLF+_
                                                   "1000 milliseconds equals 1 second. Use the ping command to test a site for reasonable response times."+$CRLF+_
                                                   "Audible alarms, use either -b (up/down changes) or -bc (constant down connections)"+$CRLF+_
                                                   "Text in the status can be changed by using -v followed by text with no spaces."+$CRLF+_
                                                   "A yellow status color can be added on a ping failure using the word -yellowlight after the location.", %MB_OK OR %MB_ICONMASK,"ICMP Monitoring program"
                                      
                                            EXIT FUNCTION
                                         END IF
                                      
                                        g_smessagetext0= "If you cannot see the bottom, press enter to send the report to clipboard."+$CRLF
                                        g_smessagetext0+="or you can close the window with the X button at the top right."+$CRLF
                                      
                                        g_smessagetext1+="The program with the command line/tail used to create this log."+$CRLF+EXE.FULL$+" "+COMMAND$+$CRLF
                                        g_smessagetext1+="Site locations and order used in the pool for ICMP monitoring program."+$CRLF
                                      
                                         FOR i=1 TO g_iicmplocations
                                           g_smessagetext1+=TRIM$(STR$(i))+". "+g_slocation(i)+$CRLF
                                           IF g_slocation(i)<>g_slocation(1) THEN g_slocationstring="Internet"
                                         NEXT i
                                         IF g_itextchange=1 AND g_stextchange<>"" THEN g_slocationstring=g_stextchange
                                         IF g_slocationstring="" THEN g_slocationstring=g_slocation(1)
                                      
                                         g_smessagetext1+="The first response of an ICMP packet in the pool creates a UP status"+$CRLF
                                         g_smessagetext1+="delay before the program starts ICMP monitoring = "+STR$(g_itdelay)+" milliseconds"+$CRLF
                                         g_smessagetext1+="timeout used for each ICMP packet sent  = "+STR$(g_itimeout)+" milliseconds"+$CRLF
                                         g_smessagetext1+="time of spaceing between each ping test  = "+STR$(g_ispaceingoficmp)+" milliseconds"+$CRLF
                                         g_smessagetext1+="loop delay between ICMP testing  = "+STR$(g_iloopdelay)+" milliseconds "+$CRLF
                                         g_smessagetext2+=$CRLF+g_slocationstring+" is the text used in the gui status bar"+$CRLF
                                         g_smessagetext2+=DATE$+" "+TIME$+" Program start time"+$CRLF
                                         IF g_itdelay>0 THEN SLEEP g_itdelay
                                      
                                         g_smessagetext2+=DATE$+" "+TIME$+" Log report start"+$CRLF+"======================"+$CRLF
                                      
                                      END FUNCTION
                                      Attached Files
                                      Last edited by Paul Purvis; 12 Apr 2012, 05:41 PM.
                                      p purvis

                                      Comment


                                      • #20
                                        This program seems to have a problem in windows 7.
                                        I will work on it but i do not even have a win 7 machine setup
                                        p purvis

                                        Comment

                                        Working...
                                        X