1-877-224-8987 | Contact Us

Using TCLSH and RSH to Ensure Full Reachability

Introduction:

The following document describes how to use the TCL shell and RSH to ensure full reachability of all IP addresses in a lab. The TCL shell (TCLSH) is found in IOS feature sets that support VoIP. The 2500 and 4000 series routers are not supported along with the Cataylst 3550 switches. RSH is available on IOS based router and switch platforms.

Overview:

TCL (Tool Control Language) is a scripting language used extensiviely by Cisco Systems to facilited the testing of various router and switch platform. More information on TCL can be found at http://www.tcl.tk.

RSH (Remote SHell) is used to execute commands on a remote device. RSH was originally developed for use in a UNIX enviroment to ease the management of multiple machines. RSH is extremely insecure and in turn is not commonly used anymore. RSH is found in the Cisco IOS and in nearly all Linux/UNIX distributions.

Hardware Used:

  • 2 Cisco Routers connected by Ethernet
  • IOS version 12.2T

Configurations:

R1:

version 12.2
!
hostname Rack1R1
!
no ip domain lookup
!
interface Loopback0
 ip address 150.1.1.1 255.255.255.0
!
interface Ethernet0/0
 ip address 10.1.1.1 255.255.255.0
!
router rip
 version 2
 network 10.0.0.0
 network 150.1.0.0
 no auto-summary
!
line con 0
line aux 0
line vty 0 4
 password cisco
 login
!
end

R2:

version 12.2
!
hostname Rack1R2
!
ip rcmd rsh-enable
ip rcmd remote-host Rack1R1 10.1.1.1 Rack1R1 enable
!
no ip domain lookup
!
interface Loopback0
 ip address 150.1.2.2 255.255.255.0
!
interface Ethernet0/0
 ip address 10.1.1.2 255.255.255.0
!
router rip
 version 2
 network 10.0.0.0
 network 150.1.0.0
 no auto-summary
!
line con 0
line aux 0
line vty 0 4
 password cisco
 login
!
!
end
TCL Script:
proc ping_all {ip} {
if {[regexp "(!!)" [exec "ping $ip"]]} {
set counter 0
exec "term len 0"
set hostname [lindex [exec rsh $ip "sho run | include hostname"] 1]
set int [exec rsh $ip "show ip int brief"]
set length [llength $int]
while {$counter<=$length} {
 set tmp [lindex $int $counter]
if {[regexp "(^\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+)" $tmp ]} {
  puts "\n"
  puts "**********************************"
  puts "* Ping $hostname [lindex $int [expr $counter - 1]]"
  puts "**********************************"
  exec "ping $tmp"
  }
 incr counter
 }
 } else {
  puts "\n\n"
  puts "IP address $ip is not reachable\n"
  set route [exec "show ip route $ip"]
  puts "Output from the show ip route command\n"
  puts "[exec "show ip route $ip"]"
 }
}

Script Breakdown :

The script reads in the IP address of the device you want to test reachability to. The script then tests to ensure that is can reach that particular IP address by trying to ping the IP address. If the ping is unsucessfull an error message is displayed like below:

Rack1R1#ping_all 150.1.4.4
IP address 150.1.4.4 is not reachable
Output from the show ip route command
% Subnet not in table
Rack1R1#

If the ping is sucessful the script RSH’s to the remote device and discovers it’s hostname along with all the IP addresses that are assigned to the interfaces of the remote device. Next the script attempts to ping the IP addresses of the remote router from the local router.

Implementation:

Rack1R1#tclsh
Rack1R1(tcl)#
Rack1R1(tcl)#proc ping_all {ip} {
+>
+> if {[regexp "(!!)" [exec "ping $ip"]]} {
+>
+>   set counter 0
+>   exec "term len 0"
+>   set hostname [lindex [exec rsh $ip "sho run | include hostname"] 1]
+>   set int [exec rsh $ip "show ip int brief"]
+>   set length [llength $int]
+>
+>   while {$counter<=$length} {
+>     set tmp [lindex $int $counter]
+>
+>     if {[regexp "(^\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+)" $tmp ]} {
+>       puts "\n\n"
+>       puts "**********************************"
+>       puts "*  Ping $hostname [lindex $int [expr $counter - 1]]"
+>       puts "**********************************"
+>       exec "ping $tmp"
+>     }
+>     incr counter
+>   }
+> } else {
+>          puts "\n"
+>          puts "IP address $ip is not reachable\n"
+>          set route [exec "show ip route $ip"]
+>          puts "Output from the show ip route command\n"
+>          puts "[exec "show ip route $ip"]"
+> }
+>}
Rack1R1(tcl)#ping_all 150.1.2.2
**********************************
*  Ping Rack1R2 Ethernet0/0
**********************************
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
**********************************
*  Ping Rack1R2 Loopback0
**********************************
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 150.1.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
Rack1R1(tcl)#

© 2004 Internetwork Expert, Inc.

New Courses from the Industry Leader in Network Training: Check Them Out!
For a limited time – 2-Year All Access Pass for just $1,499! Purchase Now!