#155074 - 2006-01-11 10:36 AM
Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Hi, I've a Kixform with a checkbox. I'm pinging the computer to see if it's powered on or not. The value of the checkbox is on or off. But it's only checking once when the Kixform is opened. How can I refresh the form so that it pings again ? Here a piece of the code:
DIM $Computer $Computer = 'NL-KDKF7PM' If Ping($Computer) $CheckBox1.Checked = "True" Else $CheckBox1.Checked = "False" EndIf
Function Ping($PC) DIM $PC Shell'%comspec% /c ping -n 1 '+$PC+' >nul' $Ping = NOT @ERROR EndFunction
$Form.Show While $Form.Visible $=Execute($Form.DoEvents()) Loop Exit 1
Thanks
|
Top
|
|
|
|
#155078 - 2006-01-11 11:31 AM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Thanks guys ! Got it working
|
Top
|
|
|
|
#155079 - 2006-01-11 12:02 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Ehhh.... Now I have another question.. I want to check several PC's and created a checkbox for every PC. But only one is checked while I'm sure (Dosbox ping)that both PC are powered on..What am I doing wrong ? Code:
$CheckPCk1 = $Form.Controls.CheckBox() $CheckPCk1.BackColor = 212,208,200 $CheckPCk1.CheckAlign = 16 $CheckPCk1.CheckState = 0 $CheckPCk1.FontSize = 8,25 $CheckPCk1.Height = 21 $CheckPCk1.Left = 105 $CheckPCk1.Text = "testpc" $CheckPCk1.Top = 105 $CheckPCk1.Width = 50
$CheckPCk2 = $Form.Controls.CheckBox() $CheckPCk2.BackColor = 212,208,200 $CheckPCk2.CheckAlign = 16 $CheckPCk2.CheckState = 0 $CheckPCk2.FontSize = 8,25 $CheckPCk2.Height = 21 $CheckPCk2.Left = 105 $CheckPCk2.Text = "" $CheckPCk2.Top = 150 $CheckPCk2.Width = 20
;KD END
$Op=SetOption('NoVarsInStrings','On')
DIM $Computer $Computer = 'NL-KDKF7PM' $Timer = $Form.Timer(500) $Timer.onTimer = 'If Ping($Computer) $CheckPCk1.Checked = "True" Else $CheckPCk1.Checked = "False" EndIf '
$Computer = 'NL-TKDBYB1L' $Timer = $Form.Timer(500) $Timer.onTimer = 'If Ping($Computer) $CheckPCk2.Checked = "True" Else $CheckPCk2.Checked = "False" EndIf '
Function Ping($PC) DIM $PC shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul' $Ping = NOT @ERROR EndFunction
$Form.Show While $Form.Visible $=Execute($Form.DoEvents()) Loop Exit 1
|
Top
|
|
|
|
#155080 - 2006-01-11 12:09 PM
Re: Loop ping ?
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
you will need seperate timers for each computer
or
make one timer that calls a function, and that function runs through an array or listview of computer names and calls the ping function
|
Top
|
|
|
|
#155081 - 2006-01-11 12:16 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Yeah was afraid array's would come up.. ;-) Don't know how to write them. Do you have an example for this ? Thanks !
|
Top
|
|
|
|
#155082 - 2006-01-11 12:36 PM
Re: Loop ping ?
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I was going to build this a while ago, I just never got around to it... I suppose I'll just start now.
|
Top
|
|
|
|
#155083 - 2006-01-11 12:42 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
I'm holding my breath... !
|
Top
|
|
|
|
#155085 - 2006-01-11 01:04 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Oke, let me post the entire code. I'm getting an error in expression on line 1.. Code:
Break On $System = CreateObject("Kixtart.System")
;KD START
$Form = $System.Form() $Form.BackColor = 212,208,200 $Form.FontSize = 8,25 $Form.Height = 585 $Form.Left = 90 $Form.Text = "Kandidaten PC's" $Form.Top = 12 $Form.Width = 354 $Test = $Form.Controls.Button() $Test.FlatStyle = 3 $Test.FontSize = 8,25 $Test.Height = 24 $Test.Left = 0 $Test.Text = " Kamer 1 (203)" $Test.Top = 105 $Test.Width = 95 $Test.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PK-Kamer1.bat"' $Label1 = $Form.Controls.Label() $Label1.BackColor = 212,208,200 $Label1.FontBold = "True" $Label1.FontSize = 12,25 $Label1.Height = 36 $Label1.Left = 30 $Label1.Text = "Klik op knop om PC op te starten" $Label1.Top = 15 $Label1.Width = 280 $Button2 = $Form.Controls.Button() $Button2.FlatStyle = 3 $Button2.FontSize = 8,25 $Button2.Height = 24 $Button2.Left = 0 $Button2.Text = "Kamer 2 (204)" $Button2.Top = 150 $Button2.Width = 94 $Button2.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1L-Kamer2.bat"' $Button3 = $Form.Controls.Button() $Button3.FontSize = 8,25 $Button3.Height = 23 $Button3.Left = 165 $Button3.Text = "TestPC-Aan" $Button3.Top = 150 $Button3.Width = 75 $Button3.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PM.bat"' $Button4 = $Form.Controls.Button() $Button4.FlatStyle = 3 $Button4.FontSize = 8,25 $Button4.Height = 24 $Button4.Left = 0 $Button4.Text = "Kamer 3 (205)" $Button4.Top = 195 $Button4.Width = 95 $Button4.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7P-Kamer3.bat"' $Button5 = $Form.Controls.Button() $Button5.FlatStyle = 3 $Button5.FontSize = 8,25 $Button5.Height = 24 $Button5.Left = 0 $Button5.Text = "Kamer 4 (206)" $Button5.Top = 240 $Button5.Width = 95 $Button5.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA8W-Kamer4.bat"' $Button6 = $Form.Controls.Button() $Button6.FlatStyle = 3 $Button6.FontSize = 8,25 $Button6.Height = 24 $Button6.Left = 0 $Button6.Text = "Kamer 5 (207)" $Button6.Top = 285 $Button6.Width = 95 $Button6.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKK0HY-Kamer5.bat"' $Button7 = $Form.Controls.Button() $Button7.FontSize = 8,25 $Button7.Height = 23 $Button7.Left = 0 $Button7.Text = "Kamer 6 (208)" $Button7.Top = 330 $Button7.Width = 95 $Button7.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1K-Kamer6.bat"' $Button8 = $Form.Controls.Button() $Button8.FlatStyle = 3 $Button8.FontSize = 8,25 $Button8.Height = 24 $Button8.Left = 0 $Button8.Text = "Kamer 7 (209)" $Button8.Top = 375 $Button8.Width = 95 $Button8.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7W-Kamer7.bat"' $Button9 = $Form.Controls.Button() $Button9.FlatStyle = 3 $Button9.FontSize = 8,25 $Button9.Height = 23 $Button9.Left = 0 $Button9.Text = "Kamer 8 (210)" $Button9.Top = 420 $Button9.Width = 95 $Button9.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1X-Kamer8.bat"' $Button10 = $Form.Controls.Button() $Button10.FlatStyle = 3 $Button10.FontSize = 8,25 $Button10.Height = 24 $Button10.Left = 0 $Button10.Text = "Kamer 9 (211)" $Button10.Top = 465 $Button10.Width = 95 $Button10.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KGX150-Kamer9.bat"' $Button12 = $Form.Controls.Button() $Button12.FontSize = 8,25 $Button12.Height = 24 $Button12.Left = 165 $Button12.Text = "TestPC-overname" $Button12.Top = 195 $Button12.Width = 111 $Button12.OnClick = 'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKF7PM"'
$CheckPCk1 = $Form.Controls.CheckBox() $CheckPCk1.BackColor = 212,208,200 $CheckPCk1.CheckAlign = 16 $CheckPCk1.CheckState = 0 $CheckPCk1.FontSize = 8,25 $CheckPCk1.Height = 21 $CheckPCk1.Left = 105 $CheckPCk1.Text = "testpc" $CheckPCk1.Top = 105 $CheckPCk1.Width = 50
$CheckPCk2 = $Form.Controls.CheckBox() $CheckPCk2.BackColor = 212,208,200 $CheckPCk2.CheckAlign = 16 $CheckPCk2.CheckState = 0 $CheckPCk2.FontSize = 8,25 $CheckPCk2.Height = 21 $CheckPCk2.Left = 105 $CheckPCk2.Text = "" $CheckPCk2.Top = 150 $CheckPCk2.Width = 20
;KD END
$Op=SetOption('NoVarsInStrings','On')
DIM $Computers $Computers = 'NL-KDKF7PM','NL-TKDBYB1L' $Timer = $Form.Timer(5000) For $count=0 to ubound($Computers) $Timer.onTimer = $Timer.onTimer + 'If Ping(' + $Computers[$count] + ') $CheckPCk' + ($count+1) + '.Checked = "True" Else $CheckPCk' + ($count+1) + '.Checked = "False" EndIf' Next
Function Ping($PC) DIM $PC shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul' $Ping = NOT @ERROR EndFunction
$Form.Show While $Form.Visible $=Execute($Form.DoEvents()) Loop Exit 1
|
Top
|
|
|
|
#155088 - 2006-01-11 02:06 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Quote:
k, your code is kinda not optimized... you could consider using listview.
or, just doing the button creation into array would ease the coding a lot.
I know it's not optimized, but I'm not expierenced enough to write it myself. although I read a lot on these Forums. I've even never heard of listview... Thanks for your time.. I'll dive into the forrest of search again and see what I can find By the way, still getting an error in expression on line 20 now Checkboxes are working ok though !
|
Top
|
|
|
|
#155089 - 2006-01-11 02:29 PM
Re: Loop ping ?
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
hey, got a bit bored and wrote this for you to try: Code:
Break On $Op=SetOption('NoVarsInStrings','On') $System = CreateObject("Kixtart.System")
;KD START
$Form = $System.Form() $Form.BackColor = 212,208,200 $Form.FontSize = 8,25 $Form.Height = 585 $Form.Left = 90 $Form.Text = "Kandidaten PC's" $Form.Top = 12 $Form.Width = 354
global $_pingers MakeKamer('NL-KDKF7PM',"Kamer 1 (203)",'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PK-Kamer1.bat"') MakeKamer('NL-TKDBYB1L',"Kamer 2 (204)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1L-Kamer2.bat"') MakeKamer('some',"Kamer 3 (205)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7P-Kamer3.bat"') MakeKamer('someother',"Kamer 4 (206)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA8W-Kamer4.bat"') MakeKamer('yep',"Kamer 5 (207)",'SHELL "\\nlmoon\apps\KandPC\NL-KDKK0HY-Kamer5.bat"') MakeKamer('basta',"Kamer 6 (208)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1K-Kamer6.bat"') MakeKamer('blaah',"Kamer 7 (209)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7W-Kamer7.bat"') MakeKamer('weirdWKSTAnames',"Kamer 8 (210)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1X-Kamer8.bat"') MakeKamer('aintThey',"Kamer 9 (211)",'SHELL "\\nlmoon\apps\KandPC\NL-KGX150-Kamer9.bat"')
$Label1 = $Form.Controls.Label() $Label1.BackColor = 212,208,200 $Label1.FontBold = "True" $Label1.FontSize = 12,25 $Label1.Height = 36 $Label1.Left = 30 $Label1.Text = "Klik op knop om PC op te starten" $Label1.Top = 15 $Label1.Width = 280
$Button3 = $Form.Controls.Button() $Button3.FontSize = 8,25 $Button3.Height = 23 $Button3.Left = 210 $Button3.Text = "TestPC-Aan" $Button3.Top = 150 $Button3.Width = 75 $Button3.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PM.bat"' $Button12 = $Form.Controls.Button() $Button12.FontSize = 8,25 $Button12.Height = 24 $Button12.Left = 210 $Button12.Text = "TestPC-overname" $Button12.Top = 195 $Button12.Width = 111 $Button12.OnClick = 'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKF7PM"'
$Timer = $Form.Timer(5000) $Timer.onTimer = 'PingEmAll()'
$Form.Show While $Form.Visible $ev = $Form.DoEvents() $ev ? $=Execute($ev) Loop Exit 1
Function MakeKamer($pcName, $inputName,$inputClick) dim $button,$checkBox if isDeclared($_GamerButton_TOP) ;is this the first time this udf is called? $_GamerButton_TOP = $_GamerButton_TOP + 45 else ;it is, lets make the var and define the start location for the button. Global $_GamerButton_TOP $_GamerButton_TOP = 105 endif
$button = $Form.Controls.Button() $button.FlatStyle = 3 $button.FontSize = 8 $button.Height = 24 $button.Left = 0 $button.Text = $inputName $button.Top = $_GamerButton_TOP $button.Width = 95 $button.OnClick = $inputClick $CheckBox = $Form.Controls.CheckBox() $CheckBox.BackColor = 212,208,200 $CheckBox.CheckAlign = 16 $CheckBox.CheckState = 0 $CheckBox.FontSize = 8 $CheckBox.Height = 21 $CheckBox.Left = 105 $CheckBox.Text = $pcName $CheckBox.Top = $_GamerButton_TOP $CheckBox.Width = 100 $CheckBox.tag = $pcName ;pinger uses this tag.
redim $_pingers[ubound($_pingers)+1] $_pingers[ubound($_pingers)] = $CheckBox endfunction
Function PingEmAll() dim $system For each $system in $_pingers If Ping($system.tag) $system.Checked = "True" Else $system.Checked = "False" EndIf Next EndFunction
Function Ping($PC) DIM $PC shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul' $Ping = NOT @ERROR EndFunction
_________________________
!download KiXnet
|
Top
|
|
|
|
#155091 - 2006-01-11 02:50 PM
Re: Loop ping ?
|
Pookie62
Fresh Scripter
Registered: 2003-10-09
Posts: 37
Loc: Netherlands
|
Wow! Thanks Jooel !! Only thing.. The form opens and after the first 5 secs a dosbox is opened echoing: PingEmAll() Then looping in that..
BTW. no such weird WKSTA names.. (lol) just the SerialNr with our country (NL before it..)
|
Top
|
|
|
|
#155093 - 2006-01-11 07:29 PM
Re: Loop ping ?
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I was working on this this morning, but had to stop to take my windstar to the transmission shop...
Would it be best to filter out the non-pingables?
This can go in one of 2 directions: 1 a subnet monitor to show what is online 2 a uptime monitor to inform if something goes down.
You really wouldn't want to be constantly pinging EVERYTHING on a subnet, so ping everything on demand or ping a few things repeatedly...
You can see what I was looking to do. If you do not enter an IP, it takes your current IP and assumes Class C subnet. Otherwise input CIDR of the target network
Code:
Break On $System = CreateObject("Kixtart.System")
;************* Form ************** $Form = $System.Form() $Form.Height = 350 $Form.Left = 37 $Form.Text = "Subnet Pinger" $Form.Top = 22 $Form.Width = 250 ;**************************************
$PanelTop = $Form.Panel() $PanelTop.BorderStyle = 1 $PanelTop.Dock = 1 $PanelTop.Height = 35 $nul = $Form.Controls.Add($PanelTop)
$PanelBottom = $Form.Panel() $PanelBottom.BorderStyle = 1 $PanelBottom.Dock = 2 $PanelBottom.Height = 25 $nul = $Form.Controls.Add($PanelBottom)
$PanelCenter = $Form.Panel() $PanelCenter.BorderStyle = 1 $PanelCenter.Dock = 5 $nul = $Form.Controls.Add($PanelCenter)
$TextBox3 = $Form.TextBox('',5,5,145,20)
$Button4 = $Form.Button('Load Subnet',160,5,75,20) $button4.OnClick = "LoadSubnet"
$ListView5 = $PanelCenter.ListView() $ListView5.Dock = 5 $ListView5.GridLines = "True" $ListView5.AllowColumnReorder = "True" $ListView5.FullRowSelect = "True"
$nul = $PanelCenter.Controls.Add($ListView5) $nul = $ListView5.Columns.Add("IPAddress",100) $nul = $ListView5.Columns.Add("Status",119)
$nul = $PanelTop.Controls.Add($TextBox3) $nul = $PanelTop.Controls.Add($Button4)
$Form.Show While $Form.Visible $=Execute($Form.DoEvents()) Loop Exit 1
Function LoadSubnet if not instr($TextBox3.Text,'.') $TextBox3.Text =join(split(@IPADDRESS0),'') endif $ListView5.Items.Clear if not instr($TextBox3.Text,"/") $TextBox3.Text = $TextBox3.Text +'/24' endif $arrIPs = EnumIPRange($TextBox3.Text) for each $ip in $arrIPs if Ping($ip) $item = $ListView5.Items.Add($IP) endif next
EndFunction
Function Ping($PC) DIM $PC shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul' $Ping = NOT @ERROR EndFunction
Function EnumIPRange($sIPaddress,optional $sNetMask) Dim $aiStartRange,$aiMaskBits,$aiEndRange[4],$iHostCount,$i Dim $cidr,$fac,$mask,$temp,$temp2,$a,$b Dim $iOctet1,$iOctet2,$iOctet3,$iOctet4 Dim $tempArray[1],$arrOctect[4]
if instr($sIPaddress,'/') $cidr=val(split($sIPaddress,'/')[1]) $sIPaddress=split($sIPaddress,'/')[0] $sNetMask='' for $a = 1 to $cidr $mask=$mask+'1' next for $a = $cidr + 1 to 32 $mask=$mask+'0' next for $a = 0 to 3 $temp=substr($mask,$a*8+1,8) $temp2=0 $fac=256 for $b=1 to 8 $fac = $fac / 2 $temp2 = $temp2 + val(substr($temp,$b,1)) * $fac next if not $a=3 $sNetMask=$sNetMask+$temp2+ '.' else $sNetMask=$sNetMask+$temp2 endif next endif
$iHostCount=1
$aiStartRange=Split($sIPaddress,".") $aiMaskBits=Split($sNetMask,".") Redim Preserve $aiStartRange[4] Redim Preserve $aiMaskBits[4]
For $i = 0 To 3 $aiMaskBits[$i] =Val($aiMaskBits[$i]) & 255 $aiStartRange[$i] =Val($aiStartRange[$i]) & $aiMaskBits[$i] $aiEndRange[$i] =$aiStartRange[$i]+(255-$aiMaskBits[$i]) $iHostCount =$iHostCount*($aiEndRange[$i]-$aiStartRange[$i]+1) Next
redim $temparray[$iHostCount] $i=0 For $iOctet1 = $aiStartRange[0] To $aiEndRange[0] For $iOctet2 = $aiStartRange[1] To $aiEndRange[1] For $iOctet3 = $aiStartRange[2] To $aiEndRange[2] For $iOctet4 = $aiStartRange[3] To $aiEndRange[3] $temparray[$i]=''+$iOctet1+'.'+$iOctet2+'.'+$iOctet3+'.'+$iOctet4 $i=$i+1 Next Next Next Next $EnumIPRange=$temparray EndFunction
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|