SHOW VPN4 Route Targets with TCL script

proc get_rt {} {
set cmdout [exec “sh ip bgp vpnv4 all | include ^\*”]

foreach line [split $cmdout “n”] {
if [regexp {([0-9]+.[0-9]+.[0-9]+.[0-9]+/[0-9]+)} $line prefix] {
puts [exec “sh ip bgp vpnv4 all $prefix | include BGP|RT”]
}
}
}

Below is how I put it in and execute it

R1#tclsh
R1(tcl)#proc get_rt {} {
+>(tcl)# set cmdout [exec “sh ip bgp vpnv4 all | include ^\*”]
+>(tcl)#
+>(tcl)# foreach line [split $cmdout “n”] {
+>(tcl)#if [regexp {([0-9]+.[0-9]+.[0-9]+.[0-9]+/[0-9]+)} $line prefix]
{
+>(tcl)#puts [exec “sh ip bgp vpnv4 all $prefix | include BGP|RT”]
+>(tcl)# }
+>(tcl)# }
+>(tcl)#}

R1(tcl)#get_rt
BGP routing table entry for 64512:10:1.2.3.0/24, version 6
Extended Community: RT:64512:10

BGP routing table entry for 64512:10:4.3.2.0/25, version 7
Extended Community: RT:64512:10

BGP routing table entry for 64512:20:2.4.0.0/16, version 8
Extended Community: RT:64512:20

BGP routing table entry for 64512:20:8.6.4.2/32, version 9
Extended Community: RT:64512:20
R1(tcl)#

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s