Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

resolve hostname in TCL script

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
Cisco Employee

Re: resolve hostname in TCL script

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

Cisco Employee

Re: resolve hostname in TCL script

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

New Member

Re: resolve hostname in TCL script

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 ?

Cisco Employee

Re: resolve hostname in TCL script

1669
Views
0
Helpful
4
Replies