Page 1 of 1 1
Topic Options
#162138 - 2006-05-19 06:41 PM RFC: PingCapture
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Please see below for my latest project...

This script is designed to take a known IP address and monitor the line between the machine running the script and the specified address. It returns (at this time) Request Timed out and TTL Expired. This was written to monitor circuits where we have intermintent failures.

It was written for KixForms.Net and KiXtart 4.50

I am still working on making the stop button work, other than that it seems to be working as expected.

Any comments and suggestions are most welcome.

Code:

;*************************************************************************
; Script Name: Ping Capture
; Author: Gargoyle
; Date: 5/19/2006
; Description: To watch a specified address for intermittent drop's via ping
;*************************************************************************


Break On
$Nul = Setoption(WrapAtEOL, ON)
$Nul = Setoption(NoVarsinStrings, ON)

;============ Build the form

$System = CreateObject("Kixforms.System")
If Not $System
$nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form1 = $System.Form()
$Form1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Form1.StartPosition = 1 ;FormStartPosition_CenterScreen
$Form1.Size = $System.Size(518,257) ;(Width,Height)
$Form1.Text = "Ping Capture"


$Label1 = $System.Label()
$Label1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label1.BorderStyle = 0 ;None
$Label1.Height = 24
$Label1.Left = 14
$Label1.Text = "Please enter the IP Address to ping"
$Label1.TextAlign = 16 ;MiddleLeft
$Label1.Top = 14
$Label1.Width = 243
$nul = $Form1.Controls.Add($Label1)

$TextBox1 = $System.TextBox()
$TextBox1.Left = 13
$TextBox1.Text = "000"
$TextBox1.MaxLength = 3
$TextBox1.Top = 45
$TextBox1.Width = 27
$nul = $Form1.Controls.Add($TextBox1)

$Label2 = $System.Label()
$Label2.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label2.BorderStyle = 0 ;None
$Label2.Left = 41
$Label2.Text = "."
$Label2.TextAlign = 16 ;MiddleLeft
$Label2.Top = 43
$Label2.Width = 8
$nul = $Form1.Controls.Add($Label2)

$TextBox2 = $System.TextBox()
$TextBox2.Left = 51
$TextBox2.Text = "000"
$TextBox2.MaxLength = 3
$TextBox2.Top = 44
$TextBox2.Width = 25
$nul = $Form1.Controls.Add($TextBox2)

$Label3 = $System.Label()
$Label3.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label3.BorderStyle = 0 ;None
$Label3.Left = 77
$Label3.Text = "."
$Label3.TextAlign = 16 ;MiddleLeft
$Label3.Top = 42
$Label3.Width = 9
$nul = $Form1.Controls.Add($Label3)

$TextBox3 = $System.TextBox()
$TextBox3.Left = 88
$TextBox3.Text = "000"
$TextBox3.MaxLength = 3
$TextBox3.Top = 44
$TextBox3.Width = 25
$nul = $Form1.Controls.Add($TextBox3)

$Label4 = $System.Label()
$Label4.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label4.BorderStyle = 0 ;None
$Label4.Left = 115
$Label4.Text = "."
$Label4.TextAlign = 16 ;MiddleLeft
$Label4.Top = 41
$Label4.Width = 9
$nul = $Form1.Controls.Add($Label4)

$TextBox5 = $System.TextBox()
$TextBox5.Left = 125
$TextBox5.Text = "000"
$TextBox5.MaxLength = 3
$TextBox5.Top = 44
$TextBox5.Width = 27
$nul = $Form1.Controls.Add($TextBox5)


;============ To be used when and if Masked Text Box
; Becomes available in KF.Net

;$MaskedTextBox = $System.MaskedTextBox()
;$MaskedTextBox.BackColor = $System.Color.FromName("LightGoldenrodYellow")
;$MaskedTextBox.Left = 13
;$MaskedTextBox.Top = 44
;$MaskedTextBox.Length = 15
;$MaskedTextBox.Mask = "[0-2][0-9][0-9].[0-2][0-9][0-9].[0-2][0-9][0-9].[0-2][0-9][0-9]"
;$MaskedTextBox.Text = "000.000.000.000"
;$nul = $Form1.Controls.Add($MaskedTextBox)

$ComboBox1 = $System.ComboBox()
$ComboBox1.DropDownWidth = 40
$ComboBox1.Height = 21
$ComboBox1.ItemHeight = 13
$ComboBox1.Left = 380
$ComboBox1.Text = "0"
$ComboBox1.Top = 48
$ComboBox1.Width = 40
$nul = $Form1.Controls.Add($ComboBox1)

$ComboBox1Item0 = $ComboBox1.Items.Add("0")
$ComboBox1Item1 = $ComboBox1.Items.Add("1")
$ComboBox1Item2 = $ComboBox1.Items.Add("2")
$ComboBox1Item3 = $ComboBox1.Items.Add("3")
$ComboBox1Item4 = $ComboBox1.Items.Add("4")
$ComboBox1Item5 = $ComboBox1.Items.Add("5")
$ComboBox1Item6 = $ComboBox1.Items.Add("6")
$ComboBox1Item7 = $ComboBox1.Items.Add("7")
$ComboBox1Item8 = $ComboBox1.Items.Add("8")
$ComboBox1Item9 = $ComboBox1.Items.Add("9")
$ComboBox1Item10 = $ComboBox1.Items.Add("10")
$ComboBox1Item11 = $ComboBox1.Items.Add("11")
$ComboBox1Item12 = $ComboBox1.Items.Add("12")
$ComboBox1Item13 = $ComboBox1.Items.Add("13")
$ComboBox1Item14 = $ComboBox1.Items.Add("14")
$ComboBox1Item15 = $ComboBox1.Items.Add("15")
$ComboBox1Item16 = $ComboBox1.Items.Add("16")
$ComboBox1Item17 = $ComboBox1.Items.Add("17")
$ComboBox1Item18 = $ComboBox1.Items.Add("18")
$ComboBox1Item19 = $ComboBox1.Items.Add("19")
$ComboBox1Item20 = $ComboBox1.Items.Add("20")
$ComboBox1Item21 = $ComboBox1.Items.Add("21")
$ComboBox1Item22 = $ComboBox1.Items.Add("22")
$ComboBox1Item23 = $ComboBox1.Items.Add("23")
$ComboBox1Item24 = $ComboBox1.Items.Add("24")

$ComboBox2 = $System.ComboBox()
$ComboBox2.DropDownWidth = 41
$ComboBox2.Height = 21
$ComboBox2.ItemHeight = 13
$ComboBox2.Left = 436
$ComboBox2.Text = "0"
$ComboBox2.Top = 47
$ComboBox2.Width = 41
$ComboBox2.SelectedIndex = 1
$nul = $Form1.Controls.Add($ComboBox2)

$ComboBox2Item0 = $ComboBox2.Items.Add("0")
$ComboBox2Item1 = $ComboBox2.Items.Add("1")
$ComboBox2Item2 = $ComboBox2.Items.Add("5")
$ComboBox2Item3 = $ComboBox2.Items.Add("10")
$ComboBox2Item4 = $ComboBox2.Items.Add("15")
$ComboBox2Item5 = $ComboBox2.Items.Add("20")
$ComboBox2Item6 = $ComboBox2.Items.Add("30")
$ComboBox2Item7 = $ComboBox2.Items.Add("45")
$ComboBox2Item8 = $ComboBox2.Items.Add("60")

$Label5 = $System.Label()
$Label5.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label5.BorderStyle = 0 ;None
$Label5.Left = 270
$Label5.Text = "Run monitor for:"
$Label5.TextAlign = 16 ;MiddleLeft
$Label5.Top = 14
$Label5.Width = 87
$nul = $Form1.Controls.Add($Label5)

$CheckBox2 = $System.CheckBox()
$CheckBox2.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$CheckBox2.FlatStyle = 1 ;Popup
$CheckBox2.Left = 19
$CheckBox2.Text = "Time Outs"
$CheckBox2.Top = 130
$CheckBox2.Checked = True
$nul = $Form1.Controls.Add($CheckBox2)



$CheckBox3 = $System.CheckBox()
$CheckBox3.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$CheckBox3.FlatStyle = 1 ;Popup
$CheckBox3.Left = 240
$CheckBox3.Text = "TTL Expired"
$CheckBox3.Top = 132
$CheckBox3.Width = 94
$CheckBox3.Checked = True
$nul = $Form1.Controls.Add($CheckBox3)

$RadioButton1 = $System.RadioButton()
$RadioButton1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$RadioButton1.FlatStyle = 1 ;Popup
$RadioButton1.Left = 29
$RadioButton1.Text = "Log to File"
$RadioButton1.Top = 81
$RadioButton1.Click = "FileLog()"
$nul = $Form1.Controls.Add($RadioButton1)

$RadioButton2 = $System.RadioButton()
$RadioButton2.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$RadioButton2.FlatStyle = 1 ;Popup
$RadioButton2.Left = 31
$RadioButton2.Text = "Log to Screen"
$RadioButton2.Top = 108
$RadioButton2.Click = "ScreenLog()"
$nul = $Form1.Controls.Add($RadioButton2)



$Label7 = $System.Label()
$Label7.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label7.BorderStyle = 0 ;None
$Label7.Left = 376
$Label7.Text = "Hours Minutes"
$Label7.TextAlign = 16 ;MiddleLeft
$Label7.Top = 14
$nul = $Form1.Controls.Add($Label7)



$Button1 = $System.Button()
$Button1.FlatStyle = 1 ;Popup
$Button1.Left = 25
$Button1.Text = "Start"
$Button1.Click = "Startup()"
$Button1.Top = 179
$Button1.Enabled = "False"
$nul = $Form1.Controls.Add($Button1)

$Button2 = $System.Button()
$Button2.FlatStyle = 1 ;Popup
$Button2.Left = 119
$Button2.Text = "Stop"
$Button2.Top = 178
$Button2.Enabled = "False"
$Button2.Click = "Stop()"
$nul = $Form1.Controls.Add($Button2)

$Button3 = $System.Button()
$Button3.BackColor = $System.Color.FromName("CornflowerBlue")
$Button3.FlatStyle = 1 ;Popup
$Button3.Left = 411
$Button3.Text = "Exit"
$Button3.Top = 178
$Button3.Click = "Done()"
$nul = $Form1.Controls.Add($Button3)

$Button4 = $System.Button()
$Button4.BackColor = $System.Color.FromName("CornflowerBlue")
$Button4.FlatStyle = 1 ;Popup
$Button4.Left = 152
$Button4.Text = "SaveAs"
$Button4.Top = 98
$Button4.Click = "Save()"
$Button4.Visible = "False"
$nul = $Form1.Controls.Add($Button4)

$Label9 = $System.Label()
$Label9.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Label9.BorderStyle = 1 ;FixedSingle
$Label9.Left = 286
$Label9.TextAlign = 16 ;MiddleLeft
$Label9.Top = 71
$nul = $Form1.Controls.Add($Label9)


$ProgressBar1 = $System.ProgressBar()
$ProgressBar1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$ProgressBar1.Left = 283
$ProgressBar1.Text = "ProgressBar1"
$ProgressBar1.Top = 97
$ProgressBar1.Width = 225
$ProgressBar1.Value = 0
$nul = $Form1.Controls.Add($ProgressBar1)

;======================= Declerations

Global $Stopme, $array[1]
$Array[0] = "nul"
$Array[1] = "nul"

;====================== Now to do something

$Form1.Show ;Displays the Form


While $Form1.Visible
$Nul = Execute($Form1.DoEvents())
Loop
Exit 0


;============= FUNCTIONS =================================

;======================== System Checks and Setup

Function StartUP()

Dim $Run, $Element

$Stopme = 0 ;Not functional yet

$Label9.Text = "Progress" ;Let the user know what we are doing

$Label9.BackColor = $System.Color.FromName("LightGoldenrodYellow")


$Element = $Textbox1.text+"."+$TextBox2.text+"."+$TextBox3.text+"."+$TextBox5.text

If $CheckBox2.Checked = 0 AND $CheckBox3.Checked = 0
$Nul = MessageBox("You did not select what to watch for","Notice")
Exit
EndIf

If $Checkbox2.Checked = -1 $Array[0] = "Request Timed Out." EndIf
If $Checkbox3.Checked = -1 $Array[1] = "TTL expired in transit" Endif

$Run = (Cint($ComboBox1.text) * 60)*60

$Run = $Run + Cint($ComboBox2.text) * 60

If $Run = 0
$Nul = MessageBox("You did not specify the amount of time to run","Notice")
Exit
EndIf

$Progressbar1.Maximum = $Run ; set the length of the progress bar

CLS ;Clear the screen to prepare for output
? "Pinging "+$Element+" Press Ctrl+C to break out"
For $ = 0 to $Run step 5
If $Stopme = 1 ; Still not working.....
Exit
EndIf

Ping($Element)

$Progressbar1.Value = $ + 1; Update progress bar
Next

;===================== Reset the form

$Button1.Enabled = "False"
$Button1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Button2.Enabled = "False"
$Button2.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$RadioButton1.Checked = 0
$RadioButton2.Checked = 0
$Label9.Text = "Stopped"
$Label9.BackColor = $System.Color.FromName("Crimson")
$TextBox1.Text = "000"
$TextBox2.Text = "000"
$TextBox3.Text = "000"
$TextBox5.Text = "000"

EndFunction

;====================== User Clicked Exit
Function Done()
Close(1)
Quit (1)
EndFunction

======================= Save to file

Function Save()
$Save = $System.SaveFileDialog()
$Save.Defaultext = "txt"
$Save.Filename = "Capture"
$Save.Filter = "*.txt"
$Save.OverwritePrompt = "True"
If $Save.Showdialog = 1
Open(1,$Save.Filename,5)
EndIf

$Button1.Enabled = "True"
$Button1.BackColor = $System.Color.FromName("SpringGreen")

$Button2.Enabled = "True"
$Button2.BackColor = $System.Color.FromName("Crimson")

EndFunction

;====================== Actual Ping stuff
Function Ping($Element)
For $ = 0 to 1
If $Array[$] <> "nul"
Shell 'CMD.EXE /c PING -n 1 '+$Element+' | find /i "'+$Array[$]+'" >nul'
If @error = 0
If $FileLog = -1
Writeline(1,$Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date + @CRLF)
? $Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date
Else
? $Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date
EndIf
Else
Sleep 2
EndIf
EndIf
Next
$Nul = Execute($Form1.DoEvents(1))
EndFunction

;======================= Still trying to get this to work
Function Stop()
$Stopme = 1
EndFunction

;======================= Set form objects to allow for File save button
Function FileLog()
$Button4.Visible = "True"
$FileLog = -1
$Button1.Enabled = "False"
$Button1.BackColor = $System.Color.FromName("LightGoldenrodYellow")
$Button2.Enabled = "False"
$Button2.BackColor = $System.Color.FromName("LightGoldenrodYellow")
EndFunction

;====================== Turn off form objects related to File Save
Function ScreenLog()
$Button4.Visible = "False"
$FileLog = 0
$Button1.Enabled = "True"
$Button1.BackColor = $System.Color.FromName("SpringGreen")

$Button2.Enabled = "True"
$Button2.BackColor = $System.Color.FromName("Crimson")
EndFunction

_________________________
Today is the tomorrow you worried about yesterday.

Top
#162139 - 2006-05-19 08:19 PM Re: RFC: PingCapture
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
FromName("LightGoldenrodYellow")

WTF?!?!?
shawn, explain.
_________________________
!

download KiXnet

Top
#162140 - 2006-05-19 08:29 PM Re: RFC: PingCapture
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
think this is the kf.net way to say :

$blarb.BackColor = "LightGoldenrodYellow"

.Net slang so to say
_________________________



Top
#162141 - 2006-05-19 08:54 PM Re: RFC: PingCapture
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, wtf is lightgoldenrodyellow?
to me it sounds like "youmuddafuddasheepshaggatrytocompainthosedarnwordstogethertopimpyourcolornames"
_________________________
!

download KiXnet

Top
#162142 - 2006-05-19 09:00 PM Re: RFC: PingCapture
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok, not the comments that I was expecting, but entertaining anyway's.

Thanks Jooel....
_________________________
Today is the tomorrow you worried about yesterday.

Top
#162143 - 2006-05-22 08:57 AM Re: RFC: PingCapture
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
String Value                Hex Value  Red Value  Green Value   Blue Value
LightGoldenrodYellow    D2FAFA     250          250              210


This is an excerpt from the .Color enumeration documentation from kf chm. the string values are string expressions that evaluate to "well-known" system colors.
It has been there for a while now, if not since the early days.
_________________________



Top
#162144 - 2006-05-22 05:00 PM Re: RFC: PingCapture
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
So are there suggestions as to the script?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#162145 - 2006-05-22 09:48 PM Re: RFC: PingCapture
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Sorry Garg,

I halfway highjacked your thread.
No, not much to comment from my side as this is kf.net and I have only an early version installed as of now and am still too much into kf.classic to even keep the dev builds of kf.net up to date... so, eh, I promise to shut up here now and I swear I won't even answer Lonks questions in here
_________________________



Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.108 seconds in which 0.083 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org