cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4243
Views
0
Helpful
4
Replies

resolve hostname in TCL script

ffischer
Level 1
Level 1

Hello,

Basic Question:

How can I do a "nslookup <hostname>" in an eem tcl ?

Background:

I need to modify the running-config by putting the same (!) ip address at several places (crypto map peers, access-lists, routes).

No Problem. Basically that already works when using IP adresses.

But now the IP adress has to be resolved by DNS. The responsible DNS server uses Round-Robin-DNS and delivers another IP with every answer.

If I use the hostname in the cli_exec, the hostname is parsed to IOS,

and IOS resolves the hostname to a different IP with every "cli_exec"; leading to different IPs in the running config.

Is there a dns command or lib available in the IOS-TCL ?

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

There is no DNS library for IOS TCL (and currently no UDP socket support to make your own). But you could do something like:

set output [exec "ping ip [info hostname] repeat 1"]

regexp {Echos to ([^,]+)} $output ignore ip

puts $ip

Sorry, I missed the keyword "eem" there. The same method will work, but you will need to modify things slightly for EEM. I wrote an EEM CLI wrapper library to help with these things which can be downloaded from http://forums.cisco.com/eforum/servlet/EEM?page=eem&fn=script&scriptId=441 . Using that library, the above would become:

set cmd "ping ip [info hostname] repeat 1"

set output [run_cli [list $cmd]]

regexp {Echos to ([^,]+)} $output ignore ip

# $ip now holds the IP address

Thanks, Joe.

We already had the "IOS ping command" idea...

As unfortunateley there seems to be no better solution without a resolver/dns lib, I will try to implement that.

btw:

Does a IOS tcl-command/tcl-library reference exist ?

Can it be found anywhere in the vastness of the CCO ?

Review Cisco Networking for a $25 gift card