For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2006 > Re: Tcl (Cisco) ping program.....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Tcl (Cisco) ping program.....
Michael A. Cleverly

2006-11-29, 7:08 pm

On Tue, 28 Nov 2006, Lag wrote:

> 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
> ......
>


Untested, but since you are on a cisco device you should have a built-in
"ping" command. (If I recall correctly the first argument is the number of
packets, the second the IP address, and it returns 1 on success or 0 on
failure.)

So something like (untested):

set n_pings 1
for {set octet 20} {$octet <= 55} {incr octet} {
set ip 192.168.1.$octet
if {[ping $n_pings $ip]} then {set result YES} else {set result NO}
puts [format "%-40s %3s" $ip $result]
}

Michael
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com