Jump to content

Help with PING script


Recommended Posts

Hi there,

I need some help with below script:

#NoTrayIcon


#include 
#include 
#include 
#Include 



HotKeySet("{ESC}", "_hkExitApp")


$hWnd = GUICreate("Form1", 300, 300, 500, 500)
GUISetBkColor(0xABABAB)
; pozycja lp, pozycja gd , szerokosc, wysokosc
$Progress1 = ""
$Progress2 = ""
$Progress3 = ""




#Region ### START Koda GUI section ### Form=C:\Users\kzajaczkowski\Desktop\Status.kxf
$hWnd = GUICreate("Ping", 428, 155, 254, 124)
$Hostname1 = GUICtrlCreateInput("ppuk_it05", 24, 24, 265, 21)
$Status1 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Yellow.ico", -1, 336, 16, 32, 32)
$Hostname2 = GUICtrlCreateInput("ppwl_fps01", 24, 64, 265, 21)
$Status2 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Yellow.ico", -1, 336, 56, 32, 32)
$Hostname3 = GUICtrlCreateInput("10.128.44.254", 24, 104, 265, 21)
$Status3 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Yellow.ico", -1, 336, 96, 32, 32)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



Do
Global $sURL= GUICtrlRead($Hostname1)
Global $sURL2= GUICtrlRead($Hostname2)
Global $sURL3= GUICtrlRead($Hostname3)
$iPing = Ping($sURL, 999)
$iPing2 = Ping($sURL2, 999)
$iPing3 = Ping($sURL3, 999)


Select



Case $iPing2 = 0
$Progress2 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Red.ico", -1, 336, 56, 32, 32)

Sleep(500)

Case $iPing2 < 999
$Progress2 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Green.ico", -1, 336, 56, 32, 32)
Sleep(500)

EndSelect
Select

Case $iPing = 0
$Progress1 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Red.ico", -1, 336, 16, 32, 32)

Sleep(500)

Case $iPing < 999
$Progress1 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Green.ico", -1, 336, 16, 32, 32)
Sleep(500)

EndSelect
Select

Case $iPing3 = 0
$Progress3 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Red.ico", -1, 336, 96, 32, 32)

Sleep(500)

Case $iPing3 < 999
$Progress3 = GUICtrlCreateIcon("C:\Users\kzajaczkowski\Desktop\Green.ico", -1, 336, 96, 32, 32)
Sleep(500)

EndSelect

Until GUIGetMsg()=$GUI_EVENT_CLOSE

Func _hkExitApp()
Exit
EndFunc

It does ping whatever is in input fields and then changes icon from default to RED/GREEN depending on ping result.

I need help with one part however, I can't figure out how to make X (close) Window button to close that form!

Please let me know how this can be archived!

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
HotKeySet("{ESC}", "_hkExitApp")
$hWnd = GUICreate("Ping", 428, 155, 254, 124)
GUISetBkColor(0xABABAB)
$Hostname1 = GUICtrlCreateInput("google.com", 64, 24, 265, 21)
$Hostname2 = GUICtrlCreateInput("facebook.com", 64, 64, 265, 21)
$Hostname3 = GUICtrlCreateInput("autoitscript.com", 64, 104, 265, 21)
$Status1 = GUICtrlCreateIcon("shell32.dll", -145, 20, 20)
$Status2 = GUICtrlCreateIcon("shell32.dll", -145, 20, 60)
$Status3 = GUICtrlCreateIcon("shell32.dll", -145, 20, 100)
GUISetState(@SW_SHOW)
Do
Sleep(100)
If Ping(GUICtrlRead($Hostname1)) Then
GUICtrlSetImage($Status1, "shell32.dll", -145)
Else
GUICtrlSetImage($Status1, "shell32.dll", -132)
EndIf
If Ping(GUICtrlRead($Hostname2)) Then
GUICtrlSetImage($Status2, "shell32.dll", -145)
Else
GUICtrlSetImage($Status2, "shell32.dll", -132)
EndIf
If Ping(GUICtrlRead($Hostname3)) Then
GUICtrlSetImage($Status3, "shell32.dll", -145)
Else
GUICtrlSetImage($Status3, "shell32.dll", -132)
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _hkExitApp()
Exit
EndFunc ;==>_hkExitApp

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
HotKeySet("{ESC}", "_hkExitApp")
$hWnd = GUICreate("Ping", 428, 155, 254, 124)
GUISetBkColor(0xABABAB)
$Hostname1 = GUICtrlCreateInput("google.com", 64, 24, 265, 21)
$Hostname2 = GUICtrlCreateInput("facebook.com", 64, 64, 265, 21)
$Hostname3 = GUICtrlCreateInput("autoitscript.com", 64, 104, 265, 21)
$Status1 = GUICtrlCreateIcon("shell32.dll", -145, 20, 20)
$Status2 = GUICtrlCreateIcon("shell32.dll", -145, 20, 60)
$Status3 = GUICtrlCreateIcon("shell32.dll", -145, 20, 100)
GUISetState(@SW_SHOW)
Do
Sleep(100)
If Ping(GUICtrlRead($Hostname1)) Then
GUICtrlSetImage($Status1, "shell32.dll", -145)
Else
GUICtrlSetImage($Status1, "shell32.dll", -132)
EndIf
If Ping(GUICtrlRead($Hostname2)) Then
GUICtrlSetImage($Status2, "shell32.dll", -145)
Else
GUICtrlSetImage($Status2, "shell32.dll", -132)
EndIf
If Ping(GUICtrlRead($Hostname3)) Then
GUICtrlSetImage($Status3, "shell32.dll", -145)
Else
GUICtrlSetImage($Status3, "shell32.dll", -132)
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _hkExitApp()
Exit
EndFunc ;==>_hkExitApp

I think it would be a little better to reduce the ping requests to a few seconds. also, It seems a little odd to ping a few servers that fast and in a loop. Especially in a loop like that will prevent the gui from working right, like not reacting to user input if one of the servers it's pinging is off line because it's waiting for the request. it's just going to freeze AutoIts thread, and it'll have the same effect as the script in the the op is having problems with. Edited by FlutterShy
Link to comment
Share on other sites

Here's another little nice trick to handle user input.

Say you start the script, itll ping some default entris after you stop typing the address for 3 seconds or press enter on any of the boxes, you can leave a box empty, it won't try pinging a null value :)

I also copy pasted an addressbar to show status.

Ping UI.rar

I think this code is authored by trancexx:

Download: PingInAnotherThread.au3

JS

I was thinking about that, but it only pings one address :P

And yeas, trancexx made that ;)

Edited by FlutterShy
Link to comment
Share on other sites

I make use of ping.exe and a temp file for non-blocking ping.

You can use AdlibRegister and the ping should not block your UI

If $ping_ok = 0, ping failed.

$ping_ok = FileGetSize(@TempDir & "autoit_ping.log")
ShellExecute('cmd',' /c type nul>%temp%autoit_ping.log & ping -w 999 -n 1 www.google.com && echo OK>%temp%autoit_ping.log',"","",@SW_HIDE)
Edited by meltice
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...