#169407 - 2006-10-13 07:54 PM
RFC: PingCapture
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Well I got all of it working with the execption of an . as a tab. Let me know what you think, and any suggestion to make it better. Code:
;************************************************************************* ; Script Name: Ping Capture ; Author: Gargoyle ; Date: 5/19/2006 ; Description: To watch a specified address for intermittent drop's via ping ;*************************************************************************
If NOT @LOGONMODE Break On EndIf
$SO=SETOPTION("Explicit", "ON") $SO=SETOPTION("NoMacrosInStrings", "ON") $SO=SETOPTION("NoVarsInStrings", "ON") $SO=SETOPTION("WrapAtEOL", "ON")
Dim $SO, $nul,$build[],$LabelLeft,$LabelText,$LabelTop,$LabelWidth,$Label,$TextboxLeft[],$ComboBoxLeft[] Dim $ComboBox2Item,$CheckboxLeft[1],$ComboBox1Item,$RadioButtonTop[1],$RadioButtonClick[1], $RadioButtonText[1] Dim $ButtonTop[3],$ButtonLeft[3],$ButtonColor[3],$ButtonText[3],$ButtonAction[3]
Global $Textbox[3], $ComboBox[1],$CheckBoxText[1],$CheckBox[1],$System,$RadioButton[1] Global $Lbl_Info, $ProgressBar1, $Timer, $Button[3] Global $Stop, $element,$LineNum,$Log2File, $Form1,$counter
;============ 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" $Form1.KeyPreview = "True"
;============ Non Changing Labels $LabelLeft = Split("12,41,77,115,270,378",",") $LabelText = Split("Please enter the IP Address to ping,.,.,.,Run monitor for:,Hours Minutes",",") $LabelTop = Split("14,41,41,41,14,14",",") $LabelWidth = Split("243,9,9,9,87,110",",")
For $counter = 0 to 5 $Label = $System.Label() $Label.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Label.BorderStyle = 0 ;None $Label.Left = Val($LabelLeft[$counter]) $Label.Text = $LabelText[$counter] $Label.TextAlign = 16 ;MiddleLeft $Label.Top = Val($LabelTop[$counter]) $Label.Width = Val($LabelWidth[$counter]) $nul = $Form1.Controls.Add($Label) Next
;============ End Non Changing Labels
;============ The label that does change
$Lbl_Info = $System.Label() $Lbl_Info.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Lbl_Info.BorderStyle = 1 ;FixedSingle $Lbl_Info.Left = 286 $Lbl_Info.TextAlign = 16 ;MiddleLeft $Lbl_Info.Top = 71 $nul = $Form1.Controls.Add($Lbl_Info)
;=========== Text Box Creation ;=========== This gives us the 4 octets of the IP Address
$Textboxleft = Split("12,51,88,125",",")
For $Counter = 0 to 3 $TextBox[$Counter] = $System.TextBox() $TextBox[$Counter].Left = $TextboxLeft[$Counter] $TextBox[$Counter].Text = "000" $TextBox[$Counter].MaxLength = 3 $TextBox[$Counter].Top = 44 $TextBox[$Counter].Width = 27 ; $TextBox[$Counter].KeyPress = "TabAlt($TextBox[$Counter].KeyCode)" $nul = $Form1.Controls.Add($TextBox[$Counter]) Next
;========== End Text Box Creation
;========== Combobox Build ;========== Combo [0] = Hours [1] = Minutes
$Build = 0,1,5,10,15,20,30,45,60 $ComboBoxleft= 380,436
For $Counter = 0 to 1 $ComboBox[$Counter] = $System.ComboBox() $ComboBox[$Counter].DropDownWidth = 41 $ComboBox[$Counter].Height = 21 $ComboBox[$Counter].ItemHeight = 13 $ComboBox[$Counter].Left = $ComboBoxLeft[$Counter] $ComboBox[$Counter].Text = "0" $ComboBox[$Counter].Top = 44 $ComboBox[$Counter].Width = 41 $ComboBox[$Counter].SelectedIndex = 1 $nul = $Form1.Controls.Add($ComboBox[$Counter]) Next
for $counter=0 to 24 $ComboBox1Item = $ComboBox[0].Items.Add($counter) next
For $counter = 0 to 8 $ComboBox2Item = $ComboBox[1].Items.Add($Build[$Counter]) Next
;=========== End ComboBox Build
;============ Checkbox Build
$CheckboxText = "Request Timed Out.","TTL expired in transit" $CheckboxLeft = 12,270
For $Counter = 0 to 1 $CheckBox[$Counter] = $System.CheckBox() $CheckBox[$Counter].BackColor = $System.Color.FromName("LightGoldenrodYellow") $CheckBox[$Counter].FlatStyle = 1 ;Popup $CheckBox[$Counter].Left = $CheckBoxLeft[$Counter] $CheckBox[$Counter].Text = $CheckBoxText[$Counter] $CheckBox[$Counter].Top = 132 $CheckBox[$Counter].Width = 150 $CheckBox[$Counter].Checked = True $nul = $Form1.Controls.Add($CheckBox[$Counter]) Next ;============ End Checkbox Build
;============ RadioButton Build $RadioButtonTop = 81,108 $RadioButtonClick = "FileLog()","ScreenLog()" $RadioButtonText = "Log to file","Log to screen"
For $Counter = 0 to 1 $RadioButton[$Counter] = $System.RadioButton() $RadioButton[$Counter].BackColor = $System.Color.FromName("LightGoldenrodYellow") $RadioButton[$Counter].FlatStyle = 1 ;Popup $RadioButton[$Counter].Left = 12 $RadioButton[$Counter].Text = $RadioButtonText[$counter] $RadioButton[$Counter].Top = $RadioButtonTop[$Counter] $RadioButton[$Counter].Click = $RadioButtonClick[$Counter] $nul = $Form1.Controls.Add($RadioButton[$Counter]) Next ;============ End RadioButton Build
;============ Button Build
$ButtonTop = 179,179,179,98 $ButtonLeft = 25,119,411,152 $ButtonColor = "","","CornFlowerBlue","CornFlowerBlue" $ButtonText = "Start", "Stop", "Exit", "SaveAs" $ButtonAction = "Startup()", "StopButton_Click()","Done()","Save()"
For $Counter = 0 to 3 $Button[$Counter] = $System.Button() $Button[$counter].BackColor = $System.Color.FromName($ButtonColor[$Counter]) $Button[$counter].FlatStyle = 1 ;Popup $Button[$counter].Left = $ButtonLeft[$counter] $Button[$counter].Text = $ButtonText[$Counter] $Button[$counter].Top = $ButtonTop[$Counter] $Button[$Counter].Click = $ButtonAction[$counter] $nul = $Form1.Controls.Add($Button[$Counter]) Next
$Button[3].Visible = "False" ;============ End Button Build
$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)
;======================= Setup $Timer = $System.Timer() $Timer.Interval = 5000 ; 5 secs $Timer.Tick = "Timer_Tick($Element)" $Log2File = "False" $LineNum = 4
;====================== 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
$Lbl_Info.Text = "Progress" ;Let the user know what we are doing
For $Counter = 0 to 3 $Element = $Element + $Textbox[$counter].Text + "." Next
If $CheckBox[0].checked = 0 AND $CheckBox[1].Checked = 0 $Nul = MessageBox("You did not select what to watch for","Notice") Exit EndIf
$Run = (Cint($ComboBox[0].text) * 60)*60 $Run = $Run + Cint($ComboBox[1].text) * 60
If $Run = 0 $Nul = MessageBox("You did not specify the amount of time to run","Notice") Exit EndIf
$Progressbar1.Maximum = $Run / ($Timer.Interval/1000) ; set the length of the progress bar CLS ? "Please do not close this window" ? "Pinging "+$Element Timer_Tick($Element)
$Timer.Start()
$Stop = 0
EndFunction
;====================== User Clicked Exit Function Done() Close(1) Quit (1) EndFunction
;===================== Timer Function Timer_Tick($Element)
Ping($Element)
$Progressbar1.Value = $Progressbar1.Value + 1; Update progress bar
If $Stop Or $ProgressBar1.Value = $ProgressBar1.Maximum $Timer.Stop() $Button[0].Enabled = "False" $Button[0].BackColor = $System.Color.FromName("LightGoldenrodYellow") $Button[1].Enabled = "False" $Button[1].BackColor = $System.Color.FromName("LightGoldenrodYellow")
$RadioButton[0].Checked = 0 $RadioButton[1].Checked = 0 $Lbl_Info.Text = "Stopped" $Lbl_Info.BackColor = $System.Color.FromName("Crimson") For $Counter = 0 to 3 $Textbox[$Counter].Text = "000" Next CLS $LineNum = 4 $ProgressBar1.Value = 0 Endif
EndFunction
;======================= Save to file
Function Save() Dim $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
$Button[0].Enabled = "True" $Button[0].BackColor = $System.Color.FromName("SpringGreen")
$Button[1].Enabled = "True" $Button[1].BackColor = $System.Color.FromName("Crimson")
EndFunction
;====================== Actual Ping stuff Function Ping($Element) Dim $ $Lbl_Info.BackColor = $System.Color.FromName("SpringGreen") $Lbl_Info.Text = "Pinging "+$Element For $ = 0 to 1 Shell 'CMD.EXE /c PING -n 1 '+$Element+' | find /i "'+$CheckBox[$].Text+'">nul' If @error = 0 If $Log2File = "True" Writeline(1,$Element + " Returned "+ $CheckBox[$].Text + " at " + @Time + " " + @Date + @CRLF) at($LineNum,0) $Element + " Returned "+ $CheckBox[$].Text + " at " + @Time + " " + @Date $LineNum= $LineNum + 1 Else at($LineNum,0) $Element + " Returned "+ $CheckBox[$].Text + " at " + @Time + " " + @Date $LineNum= $LineNum + 1 EndIf EndIf Next $Lbl_Info.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Lbl_Info.Text = "Progress"
EndFunction
;======================= Stop the ping Function StopButton_Click() $Stop = 1 EndFunction
;======================= Set form objects to allow for File save button Function FileLog() $Button[3].Visible = "True" $Log2File = "True" $Button[0].Enabled = "False" $Button[0].BackColor = $System.Color.FromName("LightGoldenrodYellow") $Button[1].Enabled = "False" $Button[1].BackColor = $System.Color.FromName("LightGoldenrodYellow") EndFunction
;====================== Turn off form objects related to File Save Function ScreenLog() $Button[3].Visible = "False" $Log2File = "False" $Button[0].Enabled = "True" $Button[0].BackColor = $System.Color.FromName("SpringGreen")
$Button[1].Enabled = "True" $Button[1].BackColor = $System.Color.FromName("Crimson") EndFunction
;====================== Allow for . to work as a tab in the text boxes for IP address ;====================== This does not work yet Function TabAlt($KeyPressed) If $KeyPressed = "OemPeriod" Select Case $TextBox[0].Focused = "True" $TextBox[1].Focus = "True" Case $TextBox[1].Focused = "True" $TextBox[2].Focus = "True" Case $TextBox[2].Focused = "True" $TextBox[3].Focus = "True" EndSelect EndIf EndFunction
Edited by Gargoyle (2006-10-18 01:14 AM)
|
Top
|
|
|
|
#169408 - 2006-10-13 08:09 PM
Re: RFC: PingCapture
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ey, why do this: Code:
$ComboBox1Item0 = $ComboBox1.Items.Add("0") $ComboBox1Item1 = $ComboBox1.Items.Add("1") ... $ComboBox1Item24 = $ComboBox1.Items.Add("24")
when you can do: Code:
$ComboBox1Item = $ComboBox1.Items.Add("0") $ComboBox1Item = $ComboBox1.Items.Add("1") ... $ComboBox1Item = $ComboBox1.Items.Add("24")
and remove all those 500 unneeded global vars.
|
Top
|
|
|
|
#169409 - 2006-10-13 08:11 PM
Re: RFC: PingCapture
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
and to shorten the script, you imho should actually do: Code:
for $counter=0 to 24 $ComboBox1Item = $ComboBox1.Items.Add($counter) next
|
Top
|
|
|
|
#169414 - 2006-10-14 05:57 PM
Re: RFC: PingCapture
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Ok, tried Jooel suggestion, and taking it a step further, and this is what I ended up with. Code:
;============ Non Changing Labels ;============ Common Elements for Labels $SO = $System.Label() $SO.BackColor = $System.Color.FromName("LightGoldenrodYellow") $SO.BorderStyle = 0 ;None $SO.TextAlign = 16 ;MiddleLeft ;============ Common Elements End
$SO.Left = 41 $SO.Text = "." $SO.Top = 43 $SO.Width = 8 $nul = $Form1.Controls.Add($SO)
$SO.Left = 77 $SO.Text = "." $SO.Top = 42 $SO.Width = 9 $nul = $Form1.Controls.Add($SO)
$SO.Left = 115 $SO.Text = "." $SO.Top = 41 $SO.Width = 9 $nul = $Form1.Controls.Add($SO)
$SO.Left = 270 $SO.Text = "Run monitor for:" $SO.Top = 14 $SO.Width = 87 $nul = $Form1.Controls.Add($SO)
$SO.Left = 376 $SO.Text = "Hours Minutes" $SO.Top = 14 $nul = $Form1.Controls.Add($SO)
$SO.Height = 24 $SO.Left = 14 $SO.Text = "Please enter the IP Address to ping" $SO.Top = 14 $SO.Width = 243 $nul = $Form1.Controls.Add($SO) ;============ End Non Changing Labels
This however did not work, and I only got the last label.. Is there a way to do what I was attempting or do I have to create the object each time?
And with that thought in mind I tried this... Code:
;Left $Opt[0,0] = 41 $Opt[1,0] = 77 $Opt[2,0] = 115 $Opt[3,0] = 270 $Opt[4,0] = 376 $Opt[5,0] = 24 ;Top $Opt[0,1] = 43 $Opt[1,1] = 43 $Opt[2,1] = 43 $Opt[3,1] = 14 $Opt[4,1] = 14 $Opt[5,1] = 14 ;Width $Opt[0,2] = 9 $Opt[1,2] = 9 $Opt[2,2] = 9 $Opt[3,2] = 87 $Opt[4,2] = 200 $Opt[5,2] = 243 ;Text $Opt[0,3] = "." $Opt[1,3] = "." $Opt[2,3] = "." $Opt[3,3] = "Run monitor for:" $Opt[4,3] = "Hours Minutes" $Opt[5,3] = "Please enter the IP address to ping"
For $Counter = 0 to 5 $SO = $System.Label() $SO.BackColor = $System.Color.FromName("LightGoldenrodYellow") $SO.BorderStyle = 0 ;None $SO.TextAlign = 16 ;MiddleLeft $SO.Left = $OPT[$Counter,0] $SO.Text = $OPT[$Counter,3] $SO.Top = $OPT[$Counter,1] $SO.Width = $OPT[$Counter,2] $nul = $Form1.Controls.Add($SO) Next
And that worked. Any ideas to make it more effecient
Edited by Gargoyle (2006-10-14 06:59 PM)
|
Top
|
|
|
|
#169415 - 2006-10-14 07:07 PM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
If you want your forms to look nice, you will want to pay attention to details, by that i mean pay close attention to the positioning of controls (left,top,width,height). To make it easier for your self and others to follow the script you should think about naming variables by their purpose.
I think that this is a little closer to what Jooel was talking about when he talked about the $Label's: Code:
;************************************************************************* ; Script Name: Ping Capture ; Author: Gargoyle ; Date: 5/19/2006 ; Description: To watch a specified address for intermittent drop's via ping ;*************************************************************************
If Not @LOGONMODE Break On EndIf
$SO=SetOption("Explicit", "ON") $SO=SetOption("NoMacrosInStrings", "ON") $SO=SetOption("NoVarsInStrings", "ON") $SO=SetOption("WrapAtEOL", "ON")
Dim $SO, $nul,$counter,$build[],$LabelLeft,$LabelText,$LabelTop,$LabelWidth,$index,$Label
Global $Textbox3, $Label4, $Textbox5, $ComboBox1, $ComboBox2, $Label5, $Checkbox2, $ComboBox2Item Global $Checkbox3, $RadioButton1, $RadioButton2, $Label7, $Button1, $Button2, $Button3 Global $Button4, $Label9, $ProgressBar1, $Timer,$Textbox1, $Label2, $TextBox2, $Label3 Global $Stop, $array[1], $element,$LineNum,$Log2File, $System, $Form1, $Label1, $ComboBox1Item
;============ 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" $Form1.KeyPreview = "True"
$LabelLeft = Split("12,41,77,115,270,378",",") $LabelText = Split("Please enter the IP Address to ping,.,.,.,Run monitor for:,Hours Minutes",",") $LabelTop = Split("14,41,41,41,14,14",",") $LabelWidth = Split("243,9,9,9,87,110",",")
For $index = 0 to 5 $Label = $System.Label() $Label.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Label.BorderStyle = 0 ;None ;$Label.Height = 24 $Label.Left = Val($LabelLeft[$index]) $Label.Text = $LabelText[$index] $Label.TextAlign = 16 ;MiddleLeft $Label.Top = Val($LabelTop[$index]) $Label.Width = Val($LabelWidth[$index]) $nul = $Form1.Controls.Add($Label) Next
$TextBox1 = $System.TextBox() $TextBox1.Left = 13 $TextBox1.Text = "000" $TextBox1.MaxLength = 3 $TextBox1.Top = 44 $TextBox1.Width = 27 $TextBox1.KeyPress = "TabAlt($TextBox1.KeyCode)"
$nul = $Form1.Controls.Add($TextBox1)
$TextBox2 = $System.TextBox() $TextBox2.Left = 51 $TextBox2.Text = "000" $TextBox2.MaxLength = 3 $TextBox2.Top = 44 $TextBox2.Width = 25 $TextBox2.KeyPress = "TabAlt($TextBox2.KeyCode)"
$nul = $Form1.Controls.Add($TextBox2)
$TextBox3 = $System.TextBox() $TextBox3.Left = 88 $TextBox3.Text = "000" $TextBox3.MaxLength = 3 $TextBox3.Top = 44 $TextBox3.Width = 25 $TextBox3.KeyPress = "TabAlt($TextBox3.KeyCode)"
$nul = $Form1.Controls.Add($TextBox3)
$TextBox5 = $System.TextBox() $TextBox5.Left = 125 $TextBox5.Text = "000" $TextBox5.MaxLength = 3 $TextBox5.Top = 44 $TextBox5.Width = 27 $TextBox5.KeyPress = "TabAlt($TextBox5.KeyCode)"
$nul = $Form1.Controls.Add($TextBox5)
$ComboBox1 = $System.ComboBox() $ComboBox1.DropDownWidth = 40 $ComboBox1.Height = 21 $ComboBox1.ItemHeight = 13 $ComboBox1.Left = 380 $ComboBox1.Text = "0" $ComboBox1.Top = 44 $ComboBox1.Width = 40 $nul = $Form1.Controls.Add($ComboBox1)
$ComboBox2 = $System.ComboBox() $ComboBox2.DropDownWidth = 41 $ComboBox2.Height = 21 $ComboBox2.ItemHeight = 13 $ComboBox2.Left = 436 $ComboBox2.Text = "0" $ComboBox2.Top = 44 $ComboBox2.Width = 41 $ComboBox2.SelectedIndex = 1 $nul = $Form1.Controls.Add($ComboBox2)
$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)
$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 = "StopButton_Click()" $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 = 270 $Label9.TextAlign = 16 ;MiddleLeft $Label9.Top = 44 $nul = $Form1.Controls.Add($Label9)
$ProgressBar1 = $System.ProgressBar() $ProgressBar1.BackColor = $System.Color.FromName("LightGoldenrodYellow") $ProgressBar1.Left = 270 $ProgressBar1.Text = "ProgressBar1" $ProgressBar1.Top = 74 $ProgressBar1.Width = 225 $ProgressBar1.Value = 0 $nul = $Form1.Controls.Add($ProgressBar1)
;======================= Setup $Timer = $System.Timer() $Timer.Interval = 5000 ; 5 secs $Timer.Tick = "Timer_Tick($Element)" $Log2File = "False"
$Array[0] = "nul" $Array[1] = "nul" $LineNum = 4 $Build = 0,1,5,10,15,20,30,45,60
For $counter = 0 to 24 $ComboBox1Item = $ComboBox1.Items.Add($counter) Next
For $counter = 0 to 8 $ComboBox2Item = $ComboBox2.Items.Add($Build[$Counter]) Next
;====================== 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 $Label9.Text = "Progress" ;Let the user know what we are doing $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 / ($Timer.Interval/1000) ; set the length of the progress bar CLS ? "Please do not close this window" ? "Pinging "+$Element Timer_Tick($Element) $Timer.Start() $Stop = 0 EndFunction
;====================== User Clicked Exit Function Done() Close(1) Quit (1) EndFunction
;===================== Timer Function Timer_Tick($Element) Ping($Element) $Progressbar1.Value = $Progressbar1.Value + 1; Update progress bar If $Stop Or $ProgressBar1.Value = $ProgressBar1.Maximum $Timer.Stop() $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" EndIf EndFunction
;======================= Save to file
Function Save() Dim $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) Dim $ $Label9.BackColor = $System.Color.FromName("SpringGreen") $Label9.Text = "Pinging "+$Element For $ = 0 to 1 If $Array[$] <> "nul" Shell 'CMD.EXE /c PING -n 1 '+$Element+' | find /i "'+$Array[$]+'">nul' If @error = 0 If $Log2File = "True" WriteLine(1,$Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date + @CRLF) At($LineNum,0) $Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date $LineNum= $LineNum + 1 Else At($LineNum,0) $Element + " Returned "+ $Array[$] + " at " + @Time + " " + @Date $LineNum= $LineNum + 1 EndIf EndIf EndIf Next $Label9.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Label9.Text = "Progress" EndFunction
;======================= Stop the ping Function StopButton_Click() $Stop = 1 EndFunction
;======================= Set form objects to allow for File save button Function FileLog() $Button4.Visible = "True" $Log2File = "True" $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" $Log2File = "False" $Button1.Enabled = "True" $Button1.BackColor = $System.Color.FromName("SpringGreen") $Button2.Enabled = "True" $Button2.BackColor = $System.Color.FromName("Crimson") EndFunction
;====================== Allow for . to work as a tab in the text boxes for IP address ;====================== This does not work yet Function TabAlt($KeyPressed) If $KeyPressed = "OemPeriod" Select Case $TextBox1.Focused = "True" $TextBox2.Focus = "True" Case $TextBox2.Focused = "True" $TextBox3.Focus = "True" Case $TextBox3.Focused = "True" $TextBox5.Focus = "True" EndSelect EndIf EndFunction
Edited by benny69 (2006-10-14 07:14 PM)
|
Top
|
|
|
|
#169416 - 2006-10-14 07:22 PM
Re: RFC: PingCapture
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
I like this Code:
$LabelLeft = Split("12,41,77,115,270,378",",") $LabelText = Split("Please enter the IP Address to ping,.,.,.,Run monitor for:,Hours Minutes",",") $LabelTop = Split("14,41,41,41,14,14",",") $LabelWidth = Split("243,9,9,9,87,110",",")
Better than what I did with this
Code:
;Left $Opt[0,0] = 41 $Opt[1,0] = 77 $Opt[2,0] = 115 $Opt[3,0] = 270 $Opt[4,0] = 376 $Opt[5,0] = 24 ;Top $Opt[0,1] = 43 $Opt[1,1] = 43 $Opt[2,1] = 43 $Opt[3,1] = 14 $Opt[4,1] = 14 $Opt[5,1] = 14 ;Width $Opt[0,2] = 9 $Opt[1,2] = 9 $Opt[2,2] = 9 $Opt[3,2] = 87 $Opt[4,2] = 200 $Opt[5,2] = 243 ;Text $Opt[0,3] = "." $Opt[1,3] = "." $Opt[2,3] = "." $Opt[3,3] = "Run monitor for:" $Opt[4,3] = "Hours Minutes" $Opt[5,3] = "Please enter the IP address to ping"
As for the names of objects, I am working on that as I clean it up. I was noticing it was difficult to read, and that is part of what I need to work on.
|
Top
|
|
|
|
#169417 - 2006-10-14 07:24 PM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
you know you can rename them while in kfd right?
Edited by benny69 (2006-10-14 09:05 PM)
|
Top
|
|
|
|
#169418 - 2006-10-14 09:45 PM
Re: RFC: PingCapture
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
k, like you found out, you can't "clone" the label. so, you need to recreate the label every round. or... you could go with something like:
Code:
For $index = 0 to 5 $Label = $Form1.Controls.Add($System.Label()) $Label.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Label.BorderStyle = 0 ;None ;$Label.Height = 24 $Label.Left = $LabelLeft[$index] $Label.Text = $LabelText[$index] $Label.TextAlign = 16 ;MiddleLeft $Label.Top = $LabelTop[$index] $Label.Width = $LabelWidth[$index] Next
like you can see, I didn't like the idea of val() in there. it should work without it. if not, redo the array code from: Code:
$LabelLeft = Split("12,41,77,115,270,378",",")
to: Code:
$LabelLeft = 12,41,77,115,270,378
|
Top
|
|
|
|
#169419 - 2006-10-14 09:47 PM
Re: RFC: PingCapture
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
but benny, I bet this code no longer loads in KFD it's a bit optimized and thus may not work. that's a problem of all editors, not just kfd.
|
Top
|
|
|
|
#169420 - 2006-10-14 09:57 PM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
lonk, i was hoping that you would lonkinize the label code ;0
|
Top
|
|
|
|
#169421 - 2006-10-14 10:33 PM
Re: RFC: PingCapture
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
it's been really long since I last coded kf.net stuff, but someone who has it registered on his machine could try this label version: Code:
For $index = 0 to 5 $Label = $Form1.Controls.Add($System.Label($LabelText[$index],$LabelLeft[$index],$LabelTop[$index],$LabelWidth[$index],24)) $Label.BackColor = $System.Color.FromName("LightGoldenrodYellow") $Label.BorderStyle = 0 ;None $Label.TextAlign = 16 ;MiddleLeft Next
|
Top
|
|
|
|
#169422 - 2006-10-14 10:45 PM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
i think that works with kf.classic but not kf.net. you don't have kf.net installed on your machine? last night i rebuilt my machine and have migrated to vista rc1. had a little trouble getting kf.net installed, i had to install .net 1.1 and then the .net 1.1 sp1 before i could install kf.net.
|
Top
|
|
|
|
#169424 - 2006-10-14 10:50 PM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
you running vista? kf.net needs .net 1.1.
|
Top
|
|
|
|
#169426 - 2006-10-15 01:31 AM
Re: RFC: PingCapture
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|