Skip to content

Instantly share code, notes, and snippets.

@NorimasaNabeta
Last active July 25, 2016 21:44
Show Gist options
  • Save NorimasaNabeta/9806742 to your computer and use it in GitHub Desktop.
Save NorimasaNabeta/9806742 to your computer and use it in GitHub Desktop.
multiple ping
# -*- mode: tcl; coding: utf-8 -*-
#
# Time-stamp: <2014-03-27 21:42:20 NorimasaNabeta>
#
# Usage:
# wish mping.tcl 10.0.1.1 10.0.1.2 10.0.1.3 10.0.1.4 ...
# <Contorl-c> quit
# \
exec wish "$0" ${1+"$@"}
set ::moveable 0
set ::X 0
set ::Y 0
set ::duts {}
array set ::timestamp { }
set cnt 1
if { $argc > 1 } {
foreach { ip } $argv {
lappend ::duts [list $cnt $ip]
incr cnt
}
} else {
foreach { ip } {
10.0.1.1
10.0.1.2
10.0.1.3
10.0.1.4
10.0.1.5
} {
lappend ::duts [list $cnt $ip]
incr cnt
}
}
proc resetTimestamp { id } {
set ::timestamp($id) [clock second]
puts "reset $id"
}
foreach { dut } $::duts {
foreach { dutid dutip } $dut { break }
set ::status$dutid "00:00 dut$dutid\($dutip\)"
label .dut$dutid -font {{Courier New} 12} -justify left -textvariable ::status$dutid
bind .dut$dutid <1> [list resetTimestamp $dutid]
# bind .dut$dutid <Double-1> [list spawn plink $dutip]
grid .dut$dutid -pady 2 -pady 2
set ::timestamp($dutid) [clock second]
}
label .info -font {{Courier New} 12} -justify left -text "Ctrl+C to quit"
grid .info -pady 2 -pady 2
wm title . "Multiple Ping"
wm attribute . -alpha 0.8
wm overrideredirect . yes
wm geometry . +50+50
bind all <Control-c> {destroy .}
bind . <ButtonPress> {set ::moveable 1; set ::X [expr %X-$::X]; set ::Y [expr %Y-$::Y]}
bind . <ButtonRelease> {set ::moveable 0; set ::X [expr %X-$::X]; set ::Y [expr %Y-$::Y]}
bind . <Motion> {if {!$::moveable} {break}; wm geometry . +[expr %X-$::X]+[expr %Y-$::Y]}
focus .
proc multiplePing {} {
foreach { dut } $::duts {
foreach { dutid dutip } $dut { break }
set tmp [clock second]
.dut$dutid configure -bg grey -fg white
update
if { [catch {exec ping -n 1 $dutip} msg] } {
.dut$dutid configure -bg tomato -fg white
} else {
if { [regexp "0% " $msg] } {
set ::timestamp($dutid) $tmp
.dut$dutid configure -bg olivedrab -fg white
}
}
set duration [clock format [expr $tmp - $::timestamp($dutid)] -format "%M:%S"]
set ::status$dutid "$duration dut$dutid\($dutip\)"
update
}
after [expr [llength $::duts] * 1000] multiplePing
}
multiplePing
# Local Variables:
# mode:tcl
# End:
#
# EOF
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment