Sign in to follow this  
Followers 0
D4rk^S0ul

Making a program less laggy

8 posts in this topic

I was wonder if it was possible to make my ip scanner i made less laggy it seems to take ages to respond to commands yet, it will keep changing ip so i know it goes past the guigetmsg commands heres code:

#include <GuiConstants.au3>

$Count = 1

GuiCreate("D4rk IP Scanner", 218, 183,-1, -1 , $DS_CONTEXTHELP)

$Input_1 = GuiCtrlCreateInput("4.148.126", 10, 10, 60, 20)
$Input_2 = GuiCtrlCreateInput("4.148.126", 10, 40, 60, 20)
$Input_3 = GuiCtrlCreateInput("1", 80, 10, 30, 20)
$Input_4 = GuiCtrlCreateInput("255", 80, 40, 30, 20)
$Label_5 = GuiCtrlCreateLabel("Google Ping", 130, 10, 80, 20)
$Label_6 = GuiCtrlCreateLabel("Yahoo Ping", 130, 40, 100, 30)
$Edit_7 = GuiCtrlCreateEdit("", 10, 70, 100, 70)
$Edit_666 = GuiCtrlCreateEdit("", 10, 1000, 100, 70)
$Input_8 = GuiCtrlCreateInput(@IPAddress1, 130, 99, 70, 20)
$Button_2 = GuiCtrlCreateButton("Ping", 130, 121, 70, 19)
$Button_1 = GuiCtrlCreateButton("Scan", 130, 70, 70, 19)

GuiSetState()

$Store = GUICtrlRead($Input_1)

GUICtrlSetState($Button_1, $GUI_DEFBUTTON)
GUICtrlSetState($Input_2, $GUI_DISABLE)

While 1
    $msg = GuiGetMsg()
    $Store2 = GUICtrlRead($Input_1)
    If $Store <> $Store2 Then
        GUICtrlSetData($Input_2, GUICtrlRead($Input_1))
    EndIf
    $P1 = Ping("www.google.com", 3000)
    If $P1 = 0 Then
        GUICtrlSetColor($Label_5, 0xff0000)
    Else
        If $P1 >= 500 Then
            GUICtrlSetColor($Label_5, 0xE27B1B)
        EndIf
        If $P1 < 1000 Then
            GUICtrlSetColor($Label_5, 0x5AB853)
        EndIf
    EndIf
    $P2 = Ping("www.yahoo.com", 2000)
    If $P2 = 0 Then
        GUICtrlSetColor($Label_6, 0xff0000)
    Else
        If $P2 >= 500 Then
            GUICtrlSetColor($Label_6, 0xE27B1B)
        EndIf
        If $P2 < 1000 Then
            GUICtrlSetColor($Label_6, 0x5AB853)
        EndIf
    EndIf
    Select
    Case $msg = $Button_2
        $P3 = Ping(GuiCtrlRead($Input_8), 2000)
        If $P3 = 0 Then
            MsgBox(16, "Ping Failed", "There was no response from this IP.")
        Else
            MsgBox(0, "Ping Success", "Ping successful, latency was " & $P3 & ".")
        EndIf
    Case $msg = $Button_1
        $Count = GUICtrlRead($Input_3)
        While 1
            GUICtrlSetData($Input_3, $Count)
            GUICtrlSetData($Button_1, "Stop")
            $msg = GuiGetMsg()
            $Ping = Ping(GUICtrlRead($Input_1) & "." & $Count, 600)
            $Count = $Count + 1
            If Not $Ping = 0 Then
                $Edit = GuiCtrlRead($Edit_666)
                GUICtrlSetData($Edit_7, $Edit & GUICtrlRead($Input_1) & "." & $Count & @CRLF)
                GUICtrlSetData($Edit_666, $Edit & GUICtrlRead($Input_1) & "." & $Count & @CRLF)
            EndIf
            If $Count = GUICtrlRead($Input_4) Then
                GUICtrlSetData($Button_1, "Scan")
                MsgBox(0, "Finished", "Finished scanning IP range.")
                ExitLoop
            EndIf
            If $msg = $Button_2 Then
                $P3 = Ping(GuiCtrlRead($Input_8), 2000)
                If $P3 = 0 Then
                    MsgBox(16, "Ping Failed", "There was no response from this IP.")
                Else
                    MsgBox(0, "Ping Success", "Ping successful, latency was " & $P3 & ".")
                EndIf
            EndIf
            If $msg = $Button_1 Then
                GUICtrlSetData($Button_1, "Scan")
                ExitLoop
            EndIf
        WEnd
    EndSelect
    Sleep(10)
WEnd
Exit

Its only a very simple thing, any help is greatly appreciated.

Share this post


Link to post
Share on other sites



I thought it doesnt go past the ping till it has recieved a answer?

Share this post


Link to post
Share on other sites

I thought it doesnt go past the ping till it has recieved a answer?

Correct ... and while they are performed, No Control of your GUI will respond to any action.

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

But if i click stop it will go through like 10 more ports before stopping it which means it has gone through the loop atleast 10 times and didnt see that the button was pressed?

Share this post


Link to post
Share on other sites

But if i click stop it will go through like 10 more ports before stopping it which means it has gone through the loop atleast 10 times and didnt see that the button was pressed?

That is what I am telling you ....

Your Clicks get lost because the script is doing other stuff.

Did you try to use the GUI OnEvent mode?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I was prob trying it wrong but it didnt work at , also it doesnt seem to loss my clicks normally it just takes like 30 seconds for them to do it.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

An ugly way to keep your pinger pinging constantly or scanning constantly while still being able to use the gui without the lag..

Try running the constant pings from another script in temp directory generated from your main script.

If the pid for the script is running then the ping is ok , if the pid isn't running then the ping failed...

Maybe you can use Control send text to your main gui from the temp run script to update the status..

Store the pid from the temp run script in an array so you can exit the constant ping by closing the process by pid on exit or whatever.

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

Global $ConPid[4]


$Count = 1

GuiCreate("D4rk IP Scanner", 218, 183,-1, -1 , $DS_CONTEXTHELP)

$Input_1 = GuiCtrlCreateInput("4.148.126", 10, 10, 60, 20)
$Input_2 = GuiCtrlCreateInput("4.148.126", 10, 40, 60, 20)
$Input_3 = GuiCtrlCreateInput("1", 80, 10, 30, 20)
$Input_4 = GuiCtrlCreateInput("255", 80, 40, 30, 20)
$Label_5 = GuiCtrlCreateLabel("Google Ping: ", 120, 10, 90, 30)
$Label_6 = GuiCtrlCreateLabel("Yahoo Ping: ", 120, 40, 90, 30)
$Edit_7 = GuiCtrlCreateEdit("", 10, 70, 100, 70)
$Edit_666 = GuiCtrlCreateEdit("", 10, 1000, 100, 70)
$Input_8 = GuiCtrlCreateInput(@IPAddress1, 130, 99, 70, 20)

$Button_2 = GuiCtrlCreateButton("Ping", 130, 121, 70, 19)
GUICtrlSetOnEvent(-1, 'Buttons')
$Button_1 = GuiCtrlCreateButton("Scan", 130, 70, 70, 19)
GUICtrlSetOnEvent(-1, 'Buttons')

GUISetOnEvent($GUI_EVENT_CLOSE, 'Close')

GuiSetState()

$Store = GUICtrlRead($Input_1)

GUICtrlSetState($Button_1, $GUI_DEFBUTTON)
GUICtrlSetState($Input_2, $GUI_DISABLE)

ConstantPing1()
ConstantPing2()

While 1
    Sleep(10)
WEnd


Func Buttons()
    Select
        Case @GUI_CtrlId = $Button_2
            $P3 = Ping(GuiCtrlRead($Input_8), 2000)
            If $P3 = 0 Then
                MsgBox(16, "Ping Failed", "There was no response from this IP.")
            Else
                MsgBox(0, "Ping Success", "Ping successful, latency was " & $P3 & ".")
            EndIf
        Case @GUI_CtrlId = $Button_1
            ConstantPing3()
    EndSelect
EndFunc


Func ConstantPing1() 
    Local $sSend, $hFile = @TempDir & '\Conping1.txt', $iPID
    $sSend = '#NoTrayIcon' & @CRLF & 'While 1' & @CRLF & '$P1 = Ping("www.google.com", 3000)' & @CRLF & 'If $P1 = 0 Then' & @CRLF &  _
            'ControlSetText("D4rk IP Scanner","",7, "Google Ping: ---")' & @CRLF & 'ElseIf $P1 <> 0 Then' & @CRLF & _
            'ControlSetText("D4rk IP Scanner","",7, "Google Ping: " & $P1)' & @CRLF & 'EndIf' & @CRLF & 'WEnd' 
    FileClose(FileOpen($hFile, 2))
    FileWrite($hFile, $sSend)
    $iPID = Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $hFile & '"', '', @SW_HIDE) ;/ErrorStdOut
    ProcessWait($iPID)
    $ConPid[1] = $iPID
    Return FileDelete($hFile)
EndFunc

Func ConstantPing2() 
    Local $sSend, $hFile = @TempDir & '\Conping2.txt', $iPID
    $sSend = '#NoTrayIcon' & @CRLF & 'While 1' & @CRLF & '$P1 = Ping("www.yahoo.com", 3000)' & @CRLF & 'If $P1 = 0 Then' & @CRLF &  _
            'ControlSetText("D4rk IP Scanner","",8, "Yahoo Ping:  ---")' & @CRLF & 'ElseIf $P1 <> 0 Then' & @CRLF & _
            'ControlSetText("D4rk IP Scanner","",8, "Yahoo Ping:  " & $P1)' & @CRLF & 'EndIf' & @CRLF & 'WEnd' 
    FileClose(FileOpen($hFile, 2))
    FileWrite($hFile, $sSend)
    $iPID = Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $hFile & '"', '', @SW_HIDE) ;/ErrorStdOut
    ProcessWait($iPID)
    $ConPid[2] = $iPID
    Return FileDelete($hFile)
EndFunc

Func ConstantPing3() 
    ;; Whatever your scan button does goes here , something similar to the other constant ping functions above I gather.
EndFunc

Func Close()
    For $c = 1 To 3
        If ProcessExists($ConPid[$c]) Then
            ProcessClose($ConPid[$c])
        EndIf
    Next
    Exit
EndFunc

Just a rough idea, but it's not pretty.

Cheers

Edit I just tried using your pinger as on event and using ControlSetText() from the temp run script to update the labels in the main script (changed the above and your script to suite) and yep the gui doesn't lag , I can run scan , ping and still be checking google and yahoo constantly.

So I have upto 3 sripts running from the main script.

Google Ping

Yahoo Ping

Scan (you'll need to add your own scan function)

I use the main gui for the standard ping of an IP.

Updated my bad example... lol

Edited by smashly

Share this post


Link to post
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
Sign in to follow this  
Followers 0