Re: Tcl (Cisco) ping program.....
- From: "Lag" <clfarris@xxxxxxxxx>
- Date: 28 Nov 2006 09:54:48 -0800
Thanks everyone......espeicially for the example code. That really
helps.
Any other comments are welcome, since I am basically starting Tcl from
scratch.
-Lag.
Uwe Klein wrote:
Earl Greida wrote:
"Lag" <clfarris@xxxxxxxxx> wrote in messageHe should be able to write a plain tclsh script for this functionality
news:1164728844.824942.173070@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm completely new to Tcl. I'm trying to come up with a program that
will be feed a list of IP addresses on the screen, one at a time (i.e.
192.168.1.20 - 192.168.1.55) and ping each IP. The program needs to
output the success or failure of the ping. This program will be
running on Cisco equipment! I really could use some help, please. And
if anyone knows any good links or books on Tcl Programming (besides
cisco.com, I've downloaded everything they have...LOL) it would be
appreciated.
Sample Output:
-----------------------------------------------------
IP Successful Ping?
-----------------------------------------------------
192.168.1.20 YES
192.168.1.21 YES
192.168.1.22 NO
192.168.1.23 YES
......
------------------------------------------------------
This program will be a fun exercise and give you good experience. You need
to use Expect and Tcl. Download/install Activestate since it includes
Expect. Buy "Exploring Expect" by Don Libes and "Practicle Programming in
Tcl/Tk" by Brent Welch.
if the cisco IOS provides a unix compatible ping command.
#################################################################
proc processinput fd {
set destip [ gets $fd ]
puts stderr xxx$destip
switch -glob -- $destip \
*q* {
exit
} default {
# exec ping with 1 packet sent and 2 sec timeout
if {[catch {exec ping -c1 -W2 $destip } res]} {
puts [format "%20s % 3s" $destip NO ]
} else {
puts [format "%20s % 3s" $destip YES ]
}
}
}
fileevent stdin readable {processinput stdin}
puts [format "%20s %s" IP RESULT]
vwait forever
#################################################################
fancy terminal handling left ....
uwe
.
- Follow-Ups:
- Re: Tcl (Cisco) ping program.....
- From: Uwe Klein
- Re: Tcl (Cisco) ping program.....
- References:
- Tcl (Cisco) ping program.....
- From: Lag
- Re: Tcl (Cisco) ping program.....
- From: Earl Greida
- Re: Tcl (Cisco) ping program.....
- From: Uwe Klein
- Tcl (Cisco) ping program.....
- Prev by Date: Re: Tcl (Cisco) ping program.....
- Next by Date: Re: Tcl (Cisco) ping program.....
- Previous by thread: Re: Tcl (Cisco) ping program.....
- Next by thread: Re: Tcl (Cisco) ping program.....
- Index(es):
Relevant Pages
|