Jump to content

Is There a Way to start one script with another?


Recommended Posts

  • Developers
1 hour ago, dascondor said:

Is the a way I can set a Button to  just ran that script?

Yes. 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

The reason for my very short answer was that I think I understand the question, but there isn't too much details to go on to help in more detail.
So what about some more details and the script you already have with the button to press?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos

Sorry Yes Here is the GUI code I built

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>


#Region ### START Koda GUI section ### Form=
$IPpong = GUICreate("IP Pinger", 572, 253, -1, -1)
$data1 = GUICtrlCreateInput("1", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$data2 = GUICtrlCreateInput("23", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $exitbutton = GUICtrlCreateButton("exitbutton", 400, 192, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $replace2 = "Second"

Global $replace3 = "Thrid"

Global $userdata1 = GUICtrlRead($data1)

Global $userdata2 = GUICtrlRead($data2)

Global $Spath = FileSaveDialog( "Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" ,"All (*.*)")

Global $IP = "IP_List.txt"

Global $sMessage = "Select a folder"


;Local $sFileSelectFolder = FileSelectFolder($sMessage, "")








Func replace2()
   MsgBox(0,"Restoring","Restoring IP_List to Orginal")
   ReplaceStringInFile( $Spath , $userdata1,$replace2 )
   ReplaceStringInFile( $Spath , $userdata2,$replace3
   MsgBox(0,"Restored Completed", "Thank you For Using IP Monitor")

EndFunc
Func replace()

 $result1 = _ReplaceStringInFile( $Spath , $replace3, $userdata2 )
 $result2 = _ReplaceStringInFile( $Spath , $replace2 ,$userdata1 )
 If $result + $result >=8 Then
    #include "test1.au3"

    EndIf

EndFunc


While(1)
    $nMsg = GUIGetMsg()
     Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $gobutton
         $Spath
         $userdata1 = GUICtrlRead($data1)
         $userdata2 = GUICtrlRead($data2)
         replace()



         replace2()

         Case $exitbutton
         exit


     EndSwitch
WEnd

And I want it to start this script with the button it doesn't like the way I am currently trying to start.

; this is to ping continuously a list of IP addresses, get and display ping result "live"
; it simulates the dos "ping -t" command but performed simultaneously on many IP
; presenting the results in a ListView highlighting not responding devices with a red box

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListviewConstants.au3>

#include 'MultiPing.au3' ; <-- take this from the following link:
; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping

Opt("GUIOnEventMode", 1)
HotKeySet("{esc}", "_button1")


Local $Win_X = 600, $Win_Y = 600 ; dimension of window
$PingGui = GUICreate("IP addresses monitor", $Win_X, $Win_Y, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui)
$listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40)
GUICtrlSetFont(-1, 6)
GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP)

; Generate colored square images
$hImage = _GUIImageList_Create(16, 16)
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 16, 16)) ; yellow
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 16, 16)) ; red
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 16, 16)) ; green

_GUICtrlListView_SetImageList($listview, $hImage, 0)

$button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20)
GUICtrlSetTip(-1, "End of program")
GUICtrlSetOnEvent(-1, "_button1")
GUISetState(@SW_SHOW)

$IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's
;
; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt
; values in the file should be separated by a semicolon, something like in the following example:
;
; hostname1;192.168.0.1
; hostname2;192.168.0.5
; hostnameX;10.59.7.200
; etc....
;
;  if values in the file are not separated by a semicolon, but another char is used, for example a comma,
;  then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",")
;
_GUICtrlListView_BeginUpdate($listview)
_GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView
_GUICtrlListView_EndUpdate($listview)

   While 1 ; continuously ping addresses of the previously loaded file (IP_List.txt)
    Sleep(10)
    ;
    ;        $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case)
    ;        |
    ;        |      1 means the IP are in the second column of the $IPlist array (first colun is nr. 0)
    ;        |      |
    ;        |      |  +-->  0 means return back an array loaded with results from all pinged addresses (responding and not responding)
    ;        |      |  |     if you use 1 then only responding addresses are loaded in the returned array [default]
    ;        |      |  |     if you use 2 then only NOT responding addresses are loaded in the returned array
    ;        |      |  |     In this case we do not need an  array to be returned, we only need to perform all pings and pass results
    ;        |      |  |     directly (on the fly) to the "_refresh" callback function that will refresh the listview
    ;        |      |  |
    ;        |      |  |  0 means NO lookup name resolution must be performed
    ;        |      |  |  |
    ;        |      |  |  |   +--> this is the callback function to be called for each pinged address each time the ping has finished
    ;        |      |  |  |   |    (see the MultiPing.au3 file for info on all passed params)
    ;        |      |  |  |   |    6 parameters are passed to this function, but only 2 are used by the called function in this case:
    ;        |      |  |  |   |    [4] roundtrip of the responding ping or -1 if IP is down
    ;        |      |  |  |   |    [5] Index (position) of this IP within the caller's passed array
    ;        |      |  |  |   |
    ;        v      v  v  v   v
    _nPing($IPlist, 1, 0, 0, "_refresh")
    ;
   WEnd

   Func _refresh($Params) ; this receive ping results and displays them in the ListView
    _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow
    Sleep(50) ; a little wait
    If $Params[4] = -1 Then ; Device not responding to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED
        _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item
    Else ; Device responds to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN
    EndIf
   EndFunc   ;==>_refresh

   Func _button1() ; Button 1 clicked
    Exit
   EndFunc   ;==>_button1

Then return back to the original script to replace the text it replace in the beginning.

Thank you so much

 

Link to comment
Share on other sites

  • Developers

Ok, a few more questions:

  1. Will the first script be compiled?
  2. is it the intent that the second script remains separate from your script as source or compiled?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Well, putting them in one is always the best approach and should be preferred when you control both pieces of source.
What is the issue merging them?
 

Here is a basic merge that could work when you have gotten rid of some coding issues. It is just to show you an approach:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListviewConstants.au3>
#include 'MultiPing.au3' ; <-- take this from the following link:
; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$IPpong = GUICreate("IP Pinger", 572, 253, -1, -1)
$data1 = GUICtrlCreateInput("1", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$data2 = GUICtrlCreateInput("23", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $exitbutton = GUICtrlCreateButton("exitbutton", 400, 192, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $replace2 = "Second"

Global $replace3 = "Thrid"

Global $userdata1 = GUICtrlRead($data1)

Global $userdata2 = GUICtrlRead($data2)

Global $Spath = FileSaveDialog("Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All (*.*)")

Global $IP = "IP_List.txt"

Global $sMessage = "Select a folder"


;Local $sFileSelectFolder = FileSelectFolder($sMessage, "")








Func replace2()
    MsgBox(0, "Restoring", "Restoring IP_List to Orginal")
    ReplaceStringInFile($Spath, $userdata1, $replace2)
    ReplaceStringInFile($Spath, $userdata2, $replace3
    MsgBox(0, "Restored Completed", "Thank you For Using IP Monitor")

EndFunc   ;==>replace2
Func replace()

    $result1 = _ReplaceStringInFile($Spath, $replace3, $userdata2)
    $result2 = _ReplaceStringInFile($Spath, $replace2, $userdata1)
    If $result + $result >= 8 Then
        #include "test1.au3"

    EndIf

EndFunc   ;==>replace


While (1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $gobutton
            $Spath
            $userdata1 = GUICtrlRead($data1)
            $userdata2 = GUICtrlRead($data2)
            replace()



            replace2()

        Case $exitbutton
            Exit


    EndSwitch
WEnd


; ##############################  second script  #############################################

; this is to ping continuously a list of IP addresses, get and display ping result "live"
; it simulates the dos "ping -t" command but performed simultaneously on many IP
; presenting the results in a ListView highlighting not responding devices with a red box


Func Main_GO()
    HotKeySet("{esc}", "_button1")
    Global $StopPing = 0
    Local $Win_X = 600, $Win_Y = 600 ; dimension of window
    $PingGui = GUICreate("IP addresses monitor", $Win_X, $Win_Y, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui)
    $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40)
    GUICtrlSetFont(-1, 6)
    GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP)

    ; Generate colored square images
    $hImage = _GUIImageList_Create(16, 16)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 16, 16)) ; yellow
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 16, 16)) ; red
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 16, 16)) ; green

    _GUICtrlListView_SetImageList($listview, $hImage, 0)

    $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20)
    GUICtrlSetTip(-1, "End of program")
    GUICtrlSetOnEvent(-1, "_button1")
    GUISetState(@SW_SHOW)

    $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's
    ;
    ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt
    ; values in the file should be separated by a semicolon, something like in the following example:
    ;
    ; hostname1;192.168.0.1
    ; hostname2;192.168.0.5
    ; hostnameX;10.59.7.200
    ; etc....
    ;
    ;  if values in the file are not separated by a semicolon, but another char is used, for example a comma,
    ;  then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",")
    ;
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView
    _GUICtrlListView_EndUpdate($listview)

    While 1 ; continuously ping addresses of the previously loaded file (IP_List.txt)
        Sleep(10)
        ;
        ;        $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case)
        ;        |
        ;        |      1 means the IP are in the second column of the $IPlist array (first colun is nr. 0)
        ;        |      |
        ;        |      |  +-->  0 means return back an array loaded with results from all pinged addresses (responding and not responding)
        ;        |      |  |     if you use 1 then only responding addresses are loaded in the returned array [default]
        ;        |      |  |     if you use 2 then only NOT responding addresses are loaded in the returned array
        ;        |      |  |     In this case we do not need an  array to be returned, we only need to perform all pings and pass results
        ;        |      |  |     directly (on the fly) to the "_refresh" callback function that will refresh the listview
        ;        |      |  |
        ;        |      |  |  0 means NO lookup name resolution must be performed
        ;        |      |  |  |
        ;        |      |  |  |   +--> this is the callback function to be called for each pinged address each time the ping has finished
        ;        |      |  |  |   |    (see the MultiPing.au3 file for info on all passed params)
        ;        |      |  |  |   |    6 parameters are passed to this function, but only 2 are used by the called function in this case:
        ;        |      |  |  |   |    [4] roundtrip of the responding ping or -1 if IP is down
        ;        |      |  |  |   |    [5] Index (position) of this IP within the caller's passed array
        ;        |      |  |  |   |
        ;        v      v  v  v   v
        _nPing($IPlist, 1, 0, 0, "_refresh")
        if $StopPing Then Return
        ;
    WEnd
    HotKeySet("{esc}")
EndFunc   ;==>Main_GO

Func _refresh($Params) ; this receive ping results and displays them in the ListView
    _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow
    Sleep(50) ; a little wait
    If $Params[4] = -1 Then ; Device not responding to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED
        _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item
    Else ; Device responds to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN
    EndIf
EndFunc   ;==>_refresh

Func _button1() ; Button 1 clicked
    $StopPing = 1
EndFunc   ;==>_button1

As said, there are still multiple syntax errors in there and would like to advice you to download the Full SciTE4AutoIt3 installer and use that as it will run au3check for you each time telling about these errors.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

So I downloaded that au3check so much better thank very much

So I'm stalling out and it won't continue on to the actually pinging. This is where it hung up when i tried putting them together. Any thoughts on where I'm going wrong

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListviewConstants.au3>
#include 'MultiPing.au3' ; <-- take this from the following link:
; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$IPpong = GUICreate("IP Pinger", 572, 253, -1, -1)
$data1 = GUICtrlCreateInput("1", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$data2 = GUICtrlCreateInput("23", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $exitbutton = GUICtrlCreateButton("exitbutton", 400, 192, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $replace2 = "Second"

Global $replace3 = "Thrid"

Global $userdata1 = GUICtrlRead($data1)

Global $userdata2 = GUICtrlRead($data2)

Global $Spath = FileSaveDialog("Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All (*.*)")

Global $IP = "IP_List.txt"

Global $sMessage = "Select a folder"

$result1 = _ReplaceStringInFile($Spath, $replace3, $userdata2)
$result2 = _ReplaceStringInFile($Spath, $replace2, $userdata1)

;Local $sFileSelectFolder = FileSelectFolder($sMessage, "")

HotKeySet("{esc}", "_button1")








While (1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $gobutton
            $userdata1 = GUICtrlRead($data1)
            $userdata2 = GUICtrlRead($data2)
            replace()



            replace2()

        Case $exitbutton
            Exit


    EndSwitch
WEnd




Func replace2()
    MsgBox(0, "Restoring", "Restoring IP_List to Orginal")
     _ReplaceStringInFile($Spath, $userdata1, $replace2)
     _ReplaceStringInFile($Spath, $userdata2, $replace3)

EndFunc   ;==>replace2

Func replace()
    FileSaveDialog("Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All (*.*)")
    _ReplaceStringInFile($Spath, $replace3, $userdata2)
    _ReplaceStringInFile($Spath, $replace2, $userdata1)
    If $result1 + $result2 >= 8 Then
        Main_GO()

    EndIf

EndFunc   ;==>replace


; ##############################  second script  #############################################

; this is to ping continuously a list of IP addresses, get and display ping result "live"
; it simulates the dos "ping -t" command but performed simultaneously on many IP
; presenting the results in a ListView highlighting not responding devices with a red box


Func Main_GO()
    HotKeySet("{esc}", "_button1")
    Global $StopPing = 0
    Local $Win_X = 600, $Win_Y = 600 ; dimension of window
    $PingGui = GUICreate("IP addresses monitor", $Win_X, $Win_Y, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui)
     Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40)
    GUICtrlSetFont(-1, 6)
    GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP)

    ; Generate colored square images
    $hImage = _GUIImageList_Create(16, 16)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 16, 16)) ; yellow
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 16, 16)) ; red
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 16, 16)) ; green

    _GUICtrlListView_SetImageList($listview, $hImage, 0)

    $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20)
    GUICtrlSetTip(-1, "End of program")
    GUICtrlSetOnEvent(-1, "_button1")
    GUISetState(@SW_SHOW)

    $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's
    ;
    ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt
    ; values in the file should be separated by a semicolon, something like in the following example:
    ;
    ; hostname1;192.168.0.1
    ; hostname2;192.168.0.5
    ; hostnameX;10.59.7.200
    ; etc....
    ;
    ;  if values in the file are not separated by a semicolon, but another char is used, for example a comma,
    ;  then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",")
    ;
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView
    _GUICtrlListView_EndUpdate($listview)

    While 1 ; continuously ping addresses of the previously loaded file (IP_List.txt)
        Sleep(10)
        ;
        ;        $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case)
        ;        |
        ;        |      1 means the IP are in the second column of the $IPlist array (first colun is nr. 0)
        ;        |      |
        ;        |      |  +-->  0 means return back an array loaded with results from all pinged addresses (responding and not responding)
        ;        |      |  |     if you use 1 then only responding addresses are loaded in the returned array [default]
        ;        |      |  |     if you use 2 then only NOT responding addresses are loaded in the returned array
        ;        |      |  |     In this case we do not need an  array to be returned, we only need to perform all pings and pass results
        ;        |      |  |     directly (on the fly) to the "_refresh" callback function that will refresh the listview
        ;        |      |  |
        ;        |      |  |  0 means NO lookup name resolution must be performed
        ;        |      |  |  |
        ;        |      |  |  |   +--> this is the callback function to be called for each pinged address each time the ping has finished
        ;        |      |  |  |   |    (see the MultiPing.au3 file for info on all passed params)
        ;        |      |  |  |   |    6 parameters are passed to this function, but only 2 are used by the called function in this case:
        ;        |      |  |  |   |    [4] roundtrip of the responding ping or -1 if IP is down
        ;        |      |  |  |   |    [5] Index (position) of this IP within the caller's passed array
        ;        |      |  |  |   |
        ;        v      v  v  v   v
        _nPing($IPlist, 1, 0, 0, "_refresh")
        if $StopPing Then Return
        ;
    WEnd
    HotKeySet("{esc}")
EndFunc   ;==>Main_GO

Func _refresh($Params) ; this receive ping results and displays them in the ListView
    _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow
    Sleep(50) ; a little wait
    If $Params[4] = -1 Then ; Device not responding to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED
        _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item
    Else ; Device responds to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN
    EndIf
EndFunc   ;==>_refresh

Func _button1() ; Button 1 clicked
    $StopPing = 1
EndFunc   ;==>_button1

 

 

Here is a sample IP_list.txt 

Router; 10.Second.Thrid.1
iPad; 10.Second.Thrid.3
Switch 1; 10.Second.Thrid.5
Switch 2; 10.Second.Thrid.6
Cell Phone; 10.Second.Thrid.7
WAP; 10.Second.Thrid.8
Computer 1; 10.Second.Thrid.9
Computer 2; 10.Second.Thrid.11
Computer 3; 10.Second.Thrid.12
AP; 10.Second.Thrid.13

It will stall out and not respond...

I'm lost

Link to comment
Share on other sites

So I got it to start Pinging screen. But the Exit button on the gui isn't working nor is the close tab you have to force it close with task manager.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListviewConstants.au3>
#include 'MultiPing.au3' ; <-- take this from the following link:
; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping



#Region ### START Koda GUI section ### Form=
$IPpong = GUICreate("IP Pinger", 572, 253, -1, -1)
$data1 = GUICtrlCreateInput("", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$data2 = GUICtrlCreateInput("", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$exitbutton = GUICtrlCreateButton("Exit", 400, 192, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $replace2 = "Second"

Global $replace3 = "Thrid"

Global $userdata1 = GUICtrlRead($data1)

Global $userdata2 = GUICtrlRead($data2)

;~ Global $Spath = FileSaveDialog("Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All (*.*)")

;~ Global $IP = "IP_List.txt"

;~ Global $sMessage = "Select a folder"

;~ $result1 = _ReplaceStringInFile($Spath, $replace3, $userdata2)

;~ $result2 = _ReplaceStringInFile($Spath, $replace2, $userdata1)

;Local $sFileSelectFolder = FileSelectFolder($sMessage, "")

HotKeySet("{esc}", "_button1")








While (1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $gobutton
            $userdata1 = GUICtrlRead($data1)
            $userdata2 = GUICtrlRead($data2)

            replace()



;~          replace2()

        Case $exitbutton
            Exit
            _button1()


    EndSwitch
WEnd




;~ Func replace2()
;~  MsgBox(0, "Restoring", "Restoring IP_List to Orginal")
;~   _ReplaceStringInFile($Spath, $userdata1, $replace2)
;~   _ReplaceStringInFile($Spath, $userdata2, $replace3)

;~ EndFunc   ;==>replace2

Func replace()
    $Spath = FileSaveDialog("Choose Your IP_List.txt", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "All (*.*)")
    _ReplaceStringInFile($Spath, $replace3, $userdata2)
    _ReplaceStringInFile($Spath, $replace2, $userdata1)

    Main_GO()
    
    _ReplaceStringInFile($Spath, $userdata1, $replace2)
    _ReplaceStringInFile($Spath, $userdata2, $replace3)



EndFunc   ;==>replace


; ##############################  second script  #############################################

; this is to ping continuously a list of IP addresses, get and display ping result "live"
; it simulates the dos "ping -t" command but performed simultaneously on many IP
; presenting the results in a ListView highlighting not responding devices with a red box


Func Main_GO()
    Opt("GUIOnEventMode", 1)
    Global $StopPing = 0
    Local $Win_X = 800, $Win_Y = 800 ; dimension of window
    $PingGui = GUICreate("IP addresses monitor", $Win_X, $Win_Y, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui)
    Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40)
    GUICtrlSetFont(-1, 6)
    GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP)

    ; Generate colored square images
    $hImage = _GUIImageList_Create(16, 16)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 16, 16)) ; yellow
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 16, 16)) ; red
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 16, 16)) ; green

    _GUICtrlListView_SetImageList($listview, $hImage, 0)

    Global $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20)
    GUICtrlSetTip(-1, "End of program")
    GUICtrlSetOnEvent(-1, "_button1")
    GUISetState(@SW_SHOW)

    $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's
    ;
    ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt
    ; values in the file should be separated by a semicolon, something like in the following example:
    ;
    ; hostname1;192.168.0.1
    ; hostname2;192.168.0.5
    ; hostnameX;10.59.7.200
    ; etc....
    ;
    ;  if values in the file are not separated by a semicolon, but another char is used, for example a comma,
    ;  then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",")
    ;
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView
    _GUICtrlListView_EndUpdate($listview)

    While 1 ; continuously ping addresses of the previously loaded file (IP_List.txt)
        Sleep(10)
        ;
        ;        $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case)
        ;        |
        ;        |      1 means the IP are in the second column of the $IPlist array (first colun is nr. 0)
        ;        |      |
        ;        |      |  +-->  0 means return back an array loaded with results from all pinged addresses (responding and not responding)
        ;        |      |  |     if you use 1 then only responding addresses are loaded in the returned array [default]
        ;        |      |  |     if you use 2 then only NOT responding addresses are loaded in the returned array
        ;        |      |  |     In this case we do not need an  array to be returned, we only need to perform all pings and pass results
        ;        |      |  |     directly (on the fly) to the "_refresh" callback function that will refresh the listview
        ;        |      |  |
        ;        |      |  |  0 means NO lookup name resolution must be performed
        ;        |      |  |  |
        ;        |      |  |  |   +--> this is the callback function to be called for each pinged address each time the ping has finished
        ;        |      |  |  |   |    (see the MultiPing.au3 file for info on all passed params)
        ;        |      |  |  |   |    6 parameters are passed to this function, but only 2 are used by the called function in this case:
        ;        |      |  |  |   |    [4] roundtrip of the responding ping or -1 if IP is down
        ;        |      |  |  |   |    [5] Index (position) of this IP within the caller's passed array
        ;        |      |  |  |   |
        ;        v      v  v  v   v
        _nPing($IPlist, 1, 0, 0, "_refresh")
        If $StopPing Then Return
        ;
    WEnd
    HotKeySet("{esc}","_button1")
EndFunc   ;==>Main_GO

Func _refresh($Params) ; this receive ping results and displays them in the ListView
    _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow
    Sleep(50) ; a little wait
    If $Params[4] = -1 Then ; Device not responding to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED
        _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item
    Else ; Device responds to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN
    EndIf
EndFunc   ;==>_refresh

Func _button1() ; Button 1 clicked
    $StopPing = 1
EndFunc   ;==>_button1

 

Link to comment
Share on other sites

Hi @dascondor,

in the merge of the 2 scripts there is a mixture of the following modes: Opt("GUIOnEventMode", 1), GUISetOnEvent() and GUIGetMsg(). Unfortunately those options are not compatible between themselves, for this reason your script hangs or doesn't reacts to buttons clicks as expected.

Your way to change the ranges of IP to select and scan different LAN is a bit strange, anyway Here is your script a bit rearranged in the hope to simplify it a bit.

it works with data stored in arrays instead of acrobatic maneuvers on the disk file....

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListviewConstants.au3>
#include 'MultiPing.au3' ; <-- take this from the following link:
; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping

; Opt("GUIOnEventMode", 1)

; ------ pinger GUI -------------------
Global $StopPing = 0
Local $Win_X = 600, $Win_Y = 600 ; dimension of window
Global $PingGui = GUICreate("IP addresses monitor", $Win_X, $Win_Y, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui)
Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40)
GUICtrlSetFont(-1, 6)
GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP)
GUISetState(@SW_HIDE) ; hidden at startup
; --------- end of pinger gui -------------

#Region ### START Koda GUI section ### Form=
$IPpong = GUICreate("IP Pinger", 572, 253, -1, -1)
Global $data1 = GUICtrlCreateInput("1", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $data2 = GUICtrlCreateInput("23", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
Global $exitbutton = GUICtrlCreateButton("exitbutton", 400, 192, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Generate colored square images
$hImage = _GUIImageList_Create(16, 16)
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 16, 16)) ; yellow
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 16, 16)) ; red
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 16, 16)) ; green

_GUICtrlListView_SetImageList($listview, $hImage, 0)

 ; Reads text file for the base list of IP's
Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt")

Global $replace2 = "Second"
Global $replace3 = "Thrid"

Global $userdata1 = GUICtrlRead($data1)
Global $userdata2 = GUICtrlRead($data2)

While (1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $gobutton
            $userdata1 = GUICtrlRead($data1)
            $userdata2 = GUICtrlRead($data2)
            ; pass the wanted new octet
            replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go

        Case $exitbutton
            Exit
            
    EndSwitch
WEnd

Func replace_And_Go($s_2, $s_3)

    ; Create a new array wit a new list of IP according to passed second and third octet
    Local $aNew_IPlist = $aBase_IPlist
    For $i = 0 To UBound($aNew_IPlist) - 1
        $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3)
    Next

    GUISetState(@SW_HIDE, $IPpong)
    GUISetState(@SW_SHOW, $PingGui)

    ; pass the new list to the pinger
    Main_GO($aNew_IPlist)

    GUISetState(@SW_HIDE, $PingGui)
    GUISetState(@SW_SHOW, $IPpong)

EndFunc   ;==>replace_And_Go

; ##############################  second script  #############################################

; this is to ping continuously a list of IP addresses, get and display ping result "live"
; it simulates the dos "ping -t" command but performed simultaneously on many IP
; presenting the results in a ListView highlighting not responding devices with a red box


Func Main_GO($IPlist)
HotKeySet("{esc}", "_button1")
    ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's
    ;
    ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt
    ; values in the file should be separated by a semicolon, something like in the following example:
    ;
    ; hostname1;192.168.0.1
    ; hostname2;192.168.0.5
    ; hostnameX;10.59.7.200
    ; etc....
    ;
    ;  if values in the file are not separated by a semicolon, but another char is used, for example a comma,
    ;  then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",")
    ;
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_DeleteAllItems($listview)
    _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView
    _GUICtrlListView_EndUpdate($listview)

    While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt)
        Sleep(10)
        ;
        ;        $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case)
        ;        |
        ;        |      1 means the IP are in the second column of the $IPlist array (first colun is nr. 0)
        ;        |      |
        ;        |      |  +-->  0 means return back an array loaded with results from all pinged addresses (responding and not responding)
        ;        |      |  |     if you use 1 then only responding addresses are loaded in the returned array [default]
        ;        |      |  |     if you use 2 then only NOT responding addresses are loaded in the returned array
        ;        |      |  |     In this case we do not need an  array to be returned, we only need to perform all pings and pass results
        ;        |      |  |     directly (on the fly) to the "_refresh" callback function that will refresh the listview
        ;        |      |  |
        ;        |      |  |  0 means NO lookup name resolution must be performed
        ;        |      |  |  |
        ;        |      |  |  |   +--> this is the callback function to be called for each pinged address each time the ping has finished
        ;        |      |  |  |   |    (see the MultiPing.au3 file for info on all passed params)
        ;        |      |  |  |   |    6 parameters are passed to this function, but only 2 are used by the called function in this case:
        ;        |      |  |  |   |    [4] roundtrip of the responding ping or -1 if IP is down
        ;        |      |  |  |   |    [5] Index (position) of this IP within the caller's passed array
        ;        |      |  |  |   |
        ;        v      v  v  v   v
        _nPing($IPlist, 1, 0, 0, "_refresh")
    WEnd
    HotKeySet("{esc}")
    $StopPing = 0
EndFunc   ;==>Main_GO

Func _refresh($Params) ; this receive ping results and displays them in the ListView
    _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow
    Sleep(50) ; a little wait
    If $Params[4] = -1 Then ; Device not responding to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED
        _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item
    Else ; Device responds to ping
        _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN
    EndIf
EndFunc   ;==>_refresh

Func _button1() ; Button 1 clicked
    $StopPing = 1
EndFunc   ;==>_button1

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

@Chimp

This is perfect. Thank you so much.

And I hate to ask but is there a way to save this to an excel file while also keeping past results.

I know I'm asking the moon of you but some code that might get me there, but it wont get the results from it.

Func _SaveToFlie()
    $FileName = FileSaveDialog("Choose a location and name for the file", @DesktopDir, "CSV (*.CSV)", 16, "IPScan Output.csv")
    If $FileName <> "" Then
        $Output = FileOpen($FileName, 1 + 8)
        FileWriteLine($Output, "IP Address,Device Name,Ping Time")
        FileWriteLine($Output, "")
        $Count = _GUICtrlListView_GetItemCount($Used)
        For $a = 0 To $Count - 1
            $Item = _GUICtrlListView_GetItemText($Used, $a, 0)
            $Oct = StringSplit($Item, ".")
            $Last = Number($Oct[4]) ; strips out any leading 0s
            $FinalIP = $Oct[1] & "." & $Oct[2] & "." & $Oct[3] & "." & $Last
            $DeviceName = _GUICtrlListView_GetItemText($Used, $a, 1)
            $PingTime = _GUICtrlListView_GetItemText($Used, $a, 2)
            FileWriteLine($Output, $FinalIP & "," & $DeviceName & "," & $PingTime)
        Next
        FileWriteLine($Output, "")
        FileWriteLine($Output, "")
        FileWriteLine($Output, "")
        FileWriteLine($Output, ",,,,Scan results saved " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
        FileWriteLine($Output, ",,,,-MaxImuM AdVaNtAgE SofTWarE (C) 2014")
        FileClose($Output)
        TrayTip("Done", "IP address list has been saved", 8, 16)
    Else
        MsgBox(16, "ERROR", "A location or file name were not chosen, nothing was saved.")
    EndIf
EndFunc   ;==>_SaveToFlie

Or Something like that that saves the file on close of the last scan.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...