Post by Tasp on Aug 7, 2022 11:31:06 GMT -5
I've always found pinging multiple devices at once a bit on a pain. having to have multiple command prompts open simultaneously.
LB and LBNet could solve this.
So I created PingThing, this uses Chris Iversons LBNet DLL, allowing you to ping upto 9 devices concurrently, without the need for 9 open CMD windows.
It's effectively a first draft, so there might be some issues.
It requires LBNet.dll in the run directory, it will create 2 files, config.txt and pinglist.txt.
As this is a first draft I haven't implemented the "Results" code yet, my intent is to create a graphical window showing a graph of addresses vs ms response.
Enjoy
LB and LBNet could solve this.
So I created PingThing, this uses Chris Iversons LBNet DLL, allowing you to ping upto 9 devices concurrently, without the need for 9 open CMD windows.
It's effectively a first draft, so there might be some issues.
It requires LBNet.dll in the run directory, it will create 2 files, config.txt and pinglist.txt.
'LBNet.dll by Chris Iverson - https://github.com/iversc/lbnet - V2.3.0
'31/07/22
'If you use this code please credit.
'Global Vars
GLOBAL i, PingTimeout, PacketSize, WindowTitle$, MaxBoxes, Pinging, PingCount
'Define Var and Sring$
MaxBoxes = 10
PingArraySize = 99999
'Max number of saved ip addresses from file is 9999 - Max checkboxs
DIM pinglist$(9999), Checkbox$(MaxBoxes), info$(0,0)
DIM ip1$(PingArraySize,1), ip2$(PingArraySize,1), ip3$(PingArraySize,1), ip4$(PingArraySize,1), ip5$(PingArraySize,1), ip6$(PingArraySize,1), ip7$(PingArraySize,1), ip8$(PingArraySize,1), ip9$(PingArraySize,1), ip10$(PingArraySize,1)
'Open pinglist file and see if there's any entries
'First test to see if file exists, if not create a blank one.
IF fileExists(DefaultDir$, "pinglist.txt") THEN
PRINT "pinglist.txt file found"
ELSE
OPEN "pinglist.txt" FOR OUTPUT AS #file
CLOSE #file
END IF
OPEN "pinglist.txt" FOR INPUT AS #file : FileIsOpen = 1
IF eof(#file) < 0 then [filedone]
[file_loop]
i = i + 1
LINE input #file, pinglist$(i)
IF eof(#file) = 0 then [file_loop]
[filedone]
pinglist$(9999) = "Custom..."
CLOSE #file : FileIsOpen = 0
'Open config file and load entries
IF fileExists(DefaultDir$, "config.txt") THEN
PRINT "config.txt file found"
ELSE
OPEN "config.txt" FOR OUTPUT AS #file
#file, "Timeout=500"
#file, "PacketSize=32"
CLOSE #file
END IF
OPEN "config.txt" FOR INPUT AS #file : FileOpen = 1
IF eof(#file) < 0 then [Config_filedone]
[Config_file_loop]
f = f + 1
LINE input #file, config$(f)
IF eof(#file) = 0 then [Config_file_loop]
[Config_filedone]
CLOSE #file : FileIsOpen = 0
PingTimeout = VAL(REMCHAR$(config$(1), "Timeout="))
PacketSize = VAL(REMCHAR$(config$(2), "PacketSize="))
'Open LBnet
CALL OpenLBNetDLL : LBNetOpen = 1
'Define Window Sizes & Placement
'NOMAINWIN
WindowTitle$ = "PingThing"
WindowWidth = 620 : WindowHeight = 400
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'Define window items
MENU #w, "Menu", "Setup", DispaySetup, "Clear Responses", ClearGraphicboxes,|, "Exit", [Close_Program]
COMBOBOX #w.c1, pinglist$(), PingList1Handler, 10, 10, 200, 40
COMBOBOX #w.c2, pinglist$(), PingList1Handler, 10, 42, 200, 40
COMBOBOX #w.c3, pinglist$(), PingList1Handler, 10, 74, 200, 40
COMBOBOX #w.c4, pinglist$(), PingList1Handler, 10, 106, 200, 40
COMBOBOX #w.c5, pinglist$(), PingList1Handler, 10, 138, 200, 40
COMBOBOX #w.c6, pinglist$(), PingList1Handler, 10, 170, 200, 40
COMBOBOX #w.c7, pinglist$(), PingList1Handler, 10, 202, 200, 40
COMBOBOX #w.c8, pinglist$(), PingList1Handler, 10, 234, 200, 40
COMBOBOX #w.c9, pinglist$(), PingList1Handler, 10, 266, 200, 40
COMBOBOX #w.c10, pinglist$(), PingList1Handler, 10, 298, 200, 40
BUTTON #w.p1, "Ping", PingButtonHandler, UL, 220, 8
BUTTON #w.p2, "Ping", PingButtonHandler, UL, 220, 40
BUTTON #w.p3, "Ping", PingButtonHandler, UL, 220, 72
BUTTON #w.p4, "Ping", PingButtonHandler, UL, 220, 104
BUTTON #w.p5, "Ping", PingButtonHandler, UL, 220, 136
BUTTON #w.p6, "Ping", PingButtonHandler, UL, 220, 168
BUTTON #w.p7, "Ping", PingButtonHandler, UL, 220, 200
BUTTON #w.p8, "Ping", PingButtonHandler, UL, 220, 232
BUTTON #w.p9, "Ping", PingButtonHandler, UL, 220, 264
BUTTON #w.p10, "Ping", PingButtonHandler, UL, 220, 296
CHECKBOX #w.b1, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 12, 20, 20
CHECKBOX #w.b2, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 44, 20, 20
CHECKBOX #w.b3, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 76, 20, 20
CHECKBOX #w.b4, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 108, 20, 20
CHECKBOX #w.b5, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 140, 20, 20
CHECKBOX #w.b6, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 172, 20, 20
CHECKBOX #w.b7, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 204, 20, 20
CHECKBOX #w.b8, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 236, 20, 20
CHECKBOX #w.b9, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 270, 20, 20
CHECKBOX #w.b10, "", CheckboxSETHandler, CheckboxRESETHandler, 280, 300, 20, 20
GRAPHICBOX #w.g1, 320, 12, 100, 20
GRAPHICBOX #w.g2, 320, 42, 100, 20
GRAPHICBOX #w.g3, 320, 74, 100, 20
GRAPHICBOX #w.g4, 320, 106, 100, 20
GRAPHICBOX #w.g5, 320, 138, 100, 20
GRAPHICBOX #w.g6, 320, 170, 100, 20
GRAPHICBOX #w.g7, 320, 202, 100, 20
GRAPHICBOX #w.g8, 320, 234, 100, 20
GRAPHICBOX #w.g9, 320, 266, 100, 20
GRAPHICBOX #w.g10, 320, 298, 100, 20
BUTTON #w.allping, "Ping All Ticked", PingTicked, UL, 430, 10, 100, 25
BUTTON #w.stop, "Stop Pinging", StopPinging, UL, 430, 40, 100, 25
BUTTON #w.results, "Results", Results, UL, 430, 70, 100, 25
STATICTEXT #w.stxt, "Status", 450, 280, 30, 18
GRAPHICBOX #w.status, 450, 298, 100, 20
'Open main window
OPEN WindowTitle$ FOR Window AS #w
#w, "trapclose [Close_Program]"
[Main.Wait]
WAIT
STOP
'If checkboxes are ticked, insert * into an array. We will check this later if the PING ALL TICKED button is pressed.
SUB CheckboxSETHandler handle$
IF VAL(RIGHT$(handle$, 2)) = 0 THEN handle.size = 1 ELSE handle.size = 2
CheckboxIndex = VAL(RIGHT$(handle$, handle.size))
Checkbox$(CheckboxIndex) = "*"
END SUB
'Remmove * from array if user unselects the checkbox.
SUB CheckboxRESETHandler handle$
IF VAL(RIGHT$(handle$, 2)) = 0 THEN handle.size = 1 ELSE handle.size = 2
CheckboxIndex = VAL(RIGHT$(handle$, handle.size))
Checkbox$(CheckboxIndex) = ""
END SUB
'Convert button handle to combobox handle and collect info from Combobox.
SUB PingButtonHandler handle$
IF VAL(RIGHT$(handle$, 2)) = 0 THEN handle.size = 1 ELSE handle.size = 2
handle$ = "#w.c" + RIGHT$(handle$, handle.size)
#handle$, "selection? PingAddress$"
IF PingAddress$ = "" THEN EXIT SUB
CALL DoPing PingAddress$, VAL(RIGHT$(handle$, handle.size))
END SUB
SUB PingList1Handler handle$
#handle$, "contents? text$"
IF text$ = "Custom..." THEN
PROMPT "Enter IP address" ; ipaddress$
IF ipaddress$ = "" THEN
PRINT
ELSE
i = i + 1
pinglist$(i) = ipaddress$
CALL ReloadCombos
#handle$, "selectindex ";i
pinglist$(9999) = "Custom..."
END IF
ELSE
PRINT
END IF
END SUB
SUB ReloadCombos
FOR handle = 1 TO MaxBoxes
handle$ = "#w.c" + STR$(handle)
#handle$, "reload"
NEXT
END SUB
SUB PingTicked handle$
IF Pinging = 0 THEN
'Run through the Checkbox array to see how many boxes are ticked.
FOR IsPingTicked = 1 TO MaxBoxes
IF Checkbox$(IsPingTicked) = "*" THEN PingTicked = PingTicked + 1
NEXT
'Check how many boxes are ticked. If there isn't any tell the user and exit the sub as theres nothing to do.
IF PingTicked = 0 THEN
NOTICE WindowTitle$ + CHR$(13) + "Nothing selected to ping!"
#w.allping, "Ping Ticked"
CALL EnableBoxes
EXIT SUB
END IF
'Create timer length based upon ping timeout, times about to ping then 1000ms safety net.
TimerValue = PingTimeout * PingTicked '+ 200
print "TimerValue "; TimerValue
CALL DisableBoxes
TIMER TimerValue, [DoPingList]
Pinging = 1
END IF
END SUB
[DoPingList]
'Check and send to DoPing
FOR IsPingTicked = 1 TO MaxBoxes
IF Checkbox$(IsPingTicked) = "*" THEN
handle$ = "#w.c" + STR$(IsPingTicked)
#handle$ "selection? PingAddress$"
IF PingAddress$ <> "" THEN
CALL DoPing PingAddress$, IsPingTicked
END IF
END IF
NEXT
WAIT
SUB DoPing PingAddress$, ID
CALL Status ID
PingCount = PingCount + 1
IF PingCount = 99999 THEN TIMER 0 : NOTICE WindowTitle$ + CHR$(13) + "Ping limit exceeded" : GOTO [Close_Program]
IF PingHost(PingAddress$, PacketSize, status, response, PingTimeout) >= 0 THEN
PRINT ID ; " " ; PingAddress$ ; " Status: " ; status ; " Response: " ; response ; "ms"
IF response >= 1 THEN
handle$ = "#w.g" ; ID
#handle$ "FILL GREEN ; PLACE 35 12 ; FONT Tahoma 10 ; BACKCOLOR GREEN ; COLOR BLACK"
#handle$ "\";response;"ms"
END IF
IF response >= 20 THEN
handle$ = "#w.g" ; ID
#handle$ "FILL YELLOW ; PLACE 35 12 ; FONT Tahoma 10 ; BACKCOLOR YELLOW ; COLOR BLACK"
#handle$ "\";response;"ms"
END IF
IF response >= 40 THEN
handle$ = "#w.g" ; ID
#handle$ "FILL 255 140 0 ; PLACE 35 12 ; FONT Tahoma 10 ; BACKCOLOR 255 140 0 ; COLOR BLACK"
#handle$ "\";response;"ms"
END IF
ELSE
PRINT ID ; " No response from "; PingAddress$
IF response = 0 THEN
handle$ = "#w.g" ; ID
#handle$ "FILL RED ; PLACE 35 12 ; FONT Tahoma 10 ; BACKCOLOR RED ; COLOR WHITE"
#handle$ "\";response;"ms"
END IF
END IF
IF status = 11003 OR response > PingTimeout THEN
handle$ = "#w.g" ; ID
#handle$ "FILL RED ; PLACE 20 12 ; FONT Tahoma 10 ; BACKCOLOR RED ; COLOR WHITE"
#handle$ "\unreachable"
END IF
IF ID = 1 THEN ip1$(PingCount,0) = PingAddress$ : ip1$(PingCount, 1) = STR$(response)
IF ID = 2 THEN ip2$(PingCount,0) = PingAddress$ : ip2$(PingCount, 1) = STR$(response)
IF ID = 3 THEN ip3$(PingCount,0) = PingAddress$ : ip3$(PingCount, 1) = STR$(response)
IF ID = 4 THEN ip4$(PingCount,0) = PingAddress$ : ip4$(PingCount, 1) = STR$(response)
IF ID = 5 THEN ip5$(PingCount,0) = PingAddress$ : ip5$(PingCount, 1) = STR$(response)
IF ID = 6 THEN ip6$(PingCount,0) = PingAddress$ : ip6$(PingCount, 1) = STR$(response)
IF ID = 7 THEN ip7$(PingCount,0) = PingAddress$ : ip7$(PingCount, 1) = STR$(response)
IF ID = 8 THEN ip8$(PingCount,0) = PingAddress$ : ip8$(PingCount, 1) = STR$(response)
IF ID = 9 THEN ip9$(PingCount,0) = PingAddress$ : ip9$(PingCount, 1) = STR$(response)
#w.status, "CLS ; UP ; GOTO 1 13 ; BACKCOLOR WHITE ; COLOR BLACK ; DOWN"
#w.status, "\Waiting..."
#w.status, "UP"
END SUB
SUB StopPinging handle$
Pinging = 0
TIMER 0
CALL EnableBoxes
END SUB
'Display config data. Basic way to display whats in the config file.
SUB DispaySetup
NOTICE WindowTitle$ + CHR$(13) + "Timeout: " ; PingTimeout ; CHR$(13) ; "Packet size: "; PacketSize ; CHR$(13) ; "Total Pings: " ; PingCount
END SUB
'Clear thegraphics boxes back to white
SUB ClearGraphicboxes
FOR c = 1 TO 10
handle$ = "#w.g" ; c
#handle$ "fill white"
NEXT
END SUB
SUB DisableBoxes
CALL ClearGraphicboxes
FOR handle = 1 TO MaxBoxes
handle$ = "#w.p" ; handle
#handle$ "!DISABLE"
handle$ = "#w.b" ; handle
#handle$ "DISABLE"
#w.allping, "!DISABLE"
NEXT
END SUB
SUB EnableBoxes
FOR handle = 1 TO MaxBoxes
handle$ = "#w.p" ; handle
#handle$ "!ENABLE"
handle$ = "#w.b" ; handle
#handle$ "ENABLE"
#w.allping, "!ENABLE"
NEXT
END SUB
SUB Status ID
IF ID = 1 THEN #w.status, "CLS ; GOTO 0 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 10 20 ; COLOR WHITE ; UP ; GOTO 1 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 2 THEN #w.status, "CLS ; GOTO 10 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 20 20 ; COLOR WHITE ; UP ; GOTO 11 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 3 THEN #w.status, "CLS ; GOTO 20 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 30 20 ; COLOR WHITE ; UP ; GOTO 21 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 4 THEN #w.status, "CLS ; GOTO 30 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 40 20 ; COLOR WHITE ; UP ; GOTO 31 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 5 THEN #w.status, "CLS ; GOTO 40 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 50 20 ; COLOR WHITE ; UP ; GOTO 41 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 6 THEN #w.status, "CLS ; GOTO 50 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 60 20 ; COLOR WHITE ; UP ; GOTO 51 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 7 THEN #w.status, "CLS ; GOTO 60 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 70 20 ; COLOR WHITE ; UP ; GOTO 61 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 8 THEN #w.status, "CLS ; GOTO 70 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 80 20 ; COLOR WHITE ; UP ; GOTO 71 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 9 THEN #w.status, "CLS ; GOTO 80 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 90 20 ; COLOR WHITE ; UP ; GOTO 81 13 ; FONT Tahoma 10 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
IF ID = 10 THEN #w.status, "CLS ; GOTO 90 0 ; DOWN ; BACKCOLOR BLUE ; BOXFILLED 100 20 ; COLOR WHITE ; UP ; GOTO 91 10 ; FONT Tahoma 5 BOLD ; DOWN" : #w.status, "\"; ID : #w.status, "COLOR BLUE ; UP"
END SUB
FUNCTION fileExists(path$, filename$)
FILES path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
END FUNCTION
SUB Results handle$
'RESUKTS SECTION TO BE COMPLETED
END SUB
'Close main window and tidy up
[Close_Program]
'Save Array before closing
IF FileIsOpen THEN CLOSE #file
OPEN "pinglist.txt" FOR OUTPUT AS #file
FOR array = 1 TO i
#file, pinglist$(array)
NEXT array
CLOSE #file
IF LBNetOpen THEN CALL CloseLBNetDLL
CLOSE #w
STOP
'******************LBNET FUNCTIONS AND SUBS********************
FUNCTION PingHost(host$, packetSize, byref status, byref msResponse, msTimeout)
STRUCT a, b AS long
STRUCT c, d AS long
a.b.struct = status
c.d.struct = msResponse
CALLDLL #LBNet, "PingHost", host$ as ptr, packetSize as long, a as STRUCT, c as STRUCT, msTimeout as long, PingHost as long
status = a.b.struct
msResponse = c.d.struct
END FUNCTION
SUB OpenLBNetDLL
OPEN "LBNet.dll" FOR DLL AS #LBNet
a = InitLBNet()
LBNetOpen = 1
End SUB
SUB CloseLBNetDLL
a = EndLBNet()
CLOSE #LBNet
LBNetOpen = 0
END SUB
FUNCTION InitLBNet()
CALLDLL #LBNet, "InitLBNet", InitLBNet AS long
END FUNCTION
FUNCTION EndLBNet()
CALLDLL #LBNet, "EndLBNet", EndLBNet AS long
END FUNCTION
As this is a first draft I haven't implemented the "Results" code yet, my intent is to create a graphical window showing a graph of addresses vs ms response.
Enjoy