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

Tclsh implementation of host - NM

Posted By:


Posted Date:

Oct 10, 2010


Network Management




Cisco-Style BSD


Tclsh script to do DNS lookups on IOS.

Script Modified Date:

Oct 10, 2010

Cisco IOS Version tested:

12.4(24)T 15.0(1)M

Cisco Products Tested:

7206 2821

Environment Variables used:

Rating Count:


Average Rating:


File Size:

4 KB

Script Info URL:

This tclsh script implements the UNIX host command on IOS. The  host.tcl script is currently limited to IPv4 A, IPv6 AAAA, and PTR  lookups only. It can also dynamically determine the DNS server by  looking at the running config. However, if you want to specify a DNS  server to use, that is also possible. To use the script, do the  following: tclsh host.tcl HOST [DNS SERVER] Where HOST is the hostname  or IP address to lookup, and DNS SERVER is an optional DNS server name  or IP address.  Add a "-6" option to do an IPv6 AAAA lookup.

New Member

Hi , thanks for the script

i hav implimented that but getting below error please help

TEST#tclsh flash:host.tcl

ERROR: No such name

TEST#tclsh flash:host.tcl

ERROR: No error

TEST#tclsh flash:host.tcl ?

LINE    <cr>

TEST#tclsh flash:host.tcl

Translating ""...domain server ( [OK]

ERROR: couldn't open socket: connection timed out


Directory of flash:/

    1  -rw-         900  May 16 2013 13:37:06 +08:00  vlan.dat

    8  -rw-       12266  May 16 2013 21:37:36 +08:00  host.tcl

    2  -rw-        3559  Jan 15 2010 10:27:22 +08:00  cpconfig-180x.cfg

    3  -rw-     2324992  Jan 15 2010 10:27:36 +08:00  cpexpress.tar

    4  -rw-        1038  Jan 15 2010 10:27:46 +08:00  home.shtml

    5  -rw-      115712  Jan 15 2010 10:27:54 +08:00  home.tar

    6  -rw-        2099   Apr 5 2013 08:27:40 +08:00  5MarchRunningconfig

    7  -rw-    30626516   Apr 5 2013 08:35:40 +08:00  c180x-adventerprisek9-mz.151-4.M6.bin

64020480 bytes total (30912512 bytes free)

Cisco Employee

Are you using VRFs and would the DNS queries have to go out a specific VRF?

New Member

I uploaded this newer version of your utility, per your suggestion.  Unfortunately I'm experiencing the same results - both network devices return empty lines upon execution.

If I run the utility from a linux host, it works like a charm.

=====[ linux ]=====
bauhaus ~/Cisco-provided-scripts $ tclsh host.tcl has address has address has address

(yes, I know these are old, but it should still work...)
=====[ 2621 ]=====
ithny-home01-2621#tclsh host.tcl        

ithny-home01-2621#sho ver
Cisco IOS Software, C2600 Software (C2600-ADVENTERPRISEK9-M), Version 12.4(10a), RELEASE SOFTWARE (fc2)
Cisco 2621XM (MPC860P) processor (revision 3.0) with 126673K/4399K bytes of memory.
ithny-home01-2621(tcl)#info patchlevel

=====[ 2811 ]=====
ithny-home01-2811r1#tclsh host.tcl

ithny-home01-2811r1#sho ver
Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 12.4(3h), RELEASE SOFTWARE (fc2)
Cisco 2811 (revision 53.51) with 512000K/12288K bytes of memory.
ithny-home01-2811r1(tcl)#info patchlevel

Neither device is doing any sort of AAA, just static passwords since  they're testing/dev systems.  Also, no fancy routing or vrfs or  anything.  Just straightforward 'ol default the  nameserver is totally reachable.  I've even tried against DNS servers on  the same subnet, I've tried letting the script read the running-config  to pull the nameserver, but all result in no difference.  All 3 of these  systems are an the same subnet/vlan.

I'm new to TCL on IOS, so am not quite sure yet how to track down why these behavior inconsistencies happen. 

Any thoughts?


Cisco Employee

Actually, the script requires a 12.4T image or higher.  There were some bugs that prevented IPv4 sockets from working correctly on earlier versions of code.

New Member

Hi All/Joseph,

I'm wondering how I go about calling this script.  I understand that this is probably inefficient, but it would be a huge help.


let say I have something along these lines,

foreach line [split [exec "show ip arp | i [0-9]\."] \n]

append output [host.tcl [lindex $line 0]],[lindex $line 0]],[lindex $line 2],[lindex $line 3]\n



and I'm going for

hostname,ip address,mac address,Vlan

hostname,ip address,mac address,Vlan

hostname,ip address,mac address,Vlan


Cisco Employee

If you add:


exec "tclsh host.tcl ..."


Then that should give you what you want.  But you could simply edit the script so that the main resolving function is called within the loop.  That would save you quite a bit of overhead.

New Member

I was going for your second solution, but the script is well over my head.  I was looking for arg0 or something like that so I can make an edit & reuse the logic, but it doesn't look like it will be that easy.

Cisco Employee

Look at the bottom of the script.  You'll see where the "host" function is called on $argv.  If you change that code to do the iteration you want, you should see the desired results.

New Member

Thanks Joseph!!!

Seriously, you've been a huge help for me.  I appreciate all of your guidance.

New Member

Hi Joseph,

I'm getting Transaction ID mismatch, almost every time.  Do you know what's causing this?  If I put that line in with an address, multiple times, it seems to about 25% of the time.

Also, $rc seems to always be 0, but it looks like $rc should be the results of the host.tcl output.  Do you know how I can capture the output into a variable?




Cisco Employee

I haven't looked at this code in a long time.  But if the transaction ID doesn't match then the DNS reply is not ours.  Are you using UDP or TCP?  TCP should definitely be more reliable.


For rc, try doing this:


return -code $result


Instead of "return -code $rc $result".

Awesome. I have tried it, it works perfect. Thanks.