PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > Programming the Internet

Programming the Internet Programming issues related to the Internet, including Winsock, CGI and ISAPI.

Reply
 
Thread Tools Display Modes
  #16  
Old Apr 5th, 2012, 06:11 PM
paul d purvis paul d purvis is offline
Member
 
Join Date: Mar 2003
Posts: 1,414
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
Reply With Quote
  #17  
Old Apr 5th, 2012, 08:24 PM
paul d purvis paul d purvis is offline
Member
 
Join Date: Mar 2003
Posts: 1,414
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
File Type: zip INTERNET.ZIP (40.9 KB, 2 views)
__________________
p purvis

Last edited by paul d purvis; Apr 5th, 2012 at 08:39 PM.
Reply With Quote
  #18  
Old Apr 5th, 2012, 09:38 PM
paul d purvis paul d purvis is offline
Member
 
Join Date: Mar 2003
Posts: 1,414
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
Reply With Quote
  #19  
Old Apr 12th, 2012, 05:38 PM
paul d purvis paul d purvis is offline
Member
 
Join Date: Mar 2003
Posts: 1,414
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
File Type: zip INTERNET.ZIP (41.1 KB, 14 views)
__________________
p purvis

Last edited by paul d purvis; Apr 12th, 2012 at 05:41 PM.
Reply With Quote
  #20  
Old Apr 27th, 2012, 07:44 AM
paul d purvis paul d purvis is offline
Member
 
Join Date: Mar 2003
Posts: 1,414
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:28 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit