resolve hostname in TCL script

Unanswered Question
Nov 22nd, 2007
User Badges:

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 ?

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Loading.
Joe Clarke Thu, 11/22/2007 - 09:58
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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

Joe Clarke Thu, 11/22/2007 - 23:09
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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

ffischer Fri, 11/23/2007 - 01:27
User Badges:

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 ?

Actions

This Discussion