06-24-2014 09:04 AM
Hello guys,
I currently have this script, it's not good, but neither I am.
Either way I'm trying to improve this script, and I want to add a command to the script, but I don't know how or where.
This script is to find devices on the network, I work with large LAN environments and some devices aren't documented yet.
The idea behind this is to ping the range of addresses and resolve their mac addresses, then it would do a traceroute to the mac address.
traceroute mac xxxx.xxxx.xxxx xxxx.xxxx.xxxx, I currently have this.
Can you guys help me to improve this and add this command to what I already have?? Almost of it is taken from this forum so I hope you can help me.
proc validate {args} {
foreach address $args {
set output [exec "ping $address"]
puts $output
if { [regexp {.!!!!} $output] } {
set output [exec "show ip arp $address"]
puts $output
}
}}
validate 10.112.0.251
proc resolve {args} {
foreach ip $args {
set result [exec "show arp | inc $ip"]
if [regexp {[a-zA-Z]+\s+\d+\.\d+\.\d+\.\d+\s+\d+\s+([0-9a-f]+\.[0-9a-f]+\.[0-9a-f]+)\s+ARPA} $result match mac ] {
set output [exec "show mac address-table address $mac"]
regexp {(\d+\s+[0-9a-f]+\.[0-9a-f]+\.[0-9a-f]+\s+[A-Z]+\s+[0-9\/a-zA-Z]+)} $output match output
puts "$ip = $output"
} else {
puts "$ip not in arp table"
}
}}
resolve 10.112.0.251
In the end I obtain this output
Exxxxxx-B1SW1(tcl)#resolve 10.112.0.251
10.112.0.251 = 11 0800.277c.39cc DYNAMIC Gi0/13
but I want to receive this as well
traceroute mac 0040.8c93.749c 0040.8c93.749c
Source 0040.8c93.749c found on E1405897-B2SW1
1 E1405897-B2SW1 (10.xx.xx.57) : Gi0/12 => Gi0/12
Destination 0040.8c93.749c found on Exxxxx-B2SW1
Layer 2 trace completed
Thanks in advance
Solved! Go to Solution.
06-24-2014 01:12 PM
It could be as simple as adding this after your puts "$ip ..." line:
set tro [exec "traceroute mac $mac $mac"]
puts "Traceroute = $tro"
06-24-2014 01:12 PM
It could be as simple as adding this after your puts "$ip ..." line:
set tro [exec "traceroute mac $mac $mac"]
puts "Traceroute = $tro"
06-25-2014 12:51 AM
Thanks men!!!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide