×

Warning message

  • Cisco Support Forums is in Read Only mode while the site is being migrated.
  • Cisco Support Forums is in Read Only mode while the site is being migrated.

Tclsh implementation of host - NM

Document

Fri, 04/22/2016 - 23:41
Nov 1st, 2011
User Badges:
  • Cisco Employee,

Posted By:

jclarke

Posted Date:

Oct 10, 2010

Category:

Network Management

Version:

1.2

License:

Cisco-Style BSD

Summary:

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:

0

Average Rating:

0

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.

Loading.
pvsrnaidu Thu, 05/16/2013 - 06:11
User Badges:

Hi , thanks for the script



i hav implimented that but getting below error please help


TEST#tclsh flash:host.tcl 195.235.125.74

ERROR: No such name


TEST#tclsh flash:host.tcl 195.235.125.74.in-addr.arpa

ERROR: No error





TEST#tclsh flash:host.tcl 195.235.125.74.in-addr.arpa kix01s01-in-f3.1e100.net ?

LINE    <cr>



TEST#tclsh flash:host.tcl 195.235.125.74.in-addr.arpa kix01s01-in-f3.1e100.net

Translating "kix01s01-in-f3.1e100.net"...domain server (8.8.8.8) [OK]

ERROR: couldn't open socket: connection timed out







TEST#dir

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)

Joe Clarke Thu, 05/16/2013 - 08:16
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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

chris.moody Sun, 12/08/2013 - 12:57
User Badges:

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.

ex>
=====[ linux ]=====
bauhaus ~/Cisco-provided-scripts $ tclsh host.tcl www.google.com 8.8.8.8
www.google.com has address 74.125.225.113
www.google.com has address 74.125.225.112
www.google.com has address 74.125.225.114
...
=====


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

ithny-home01-2621#
--
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
8.3.4
ithny-home01-2621(tcl)#
=====


=====[ 2811 ]=====
ithny-home01-2811r1#tclsh host.tcl www.google.com 8.8.8.8
ERROR:


ithny-home01-2811r1#
--
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
8.3.4
=====

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 gateways...so the 8.8.8.8  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?

Cheers,
-Chris

Joe Clarke Sun, 12/08/2013 - 13:01
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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.

Cory Anderson Tue, 11/18/2014 - 22:03
User Badges:

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

etc....

Joe Clarke Wed, 11/19/2014 - 09:45
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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.

Cory Anderson Wed, 11/19/2014 - 10:55
User Badges:

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.

Joe Clarke Wed, 11/19/2014 - 10:57
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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.

Cory Anderson Wed, 11/19/2014 - 15:08
User Badges:

Thanks Joseph!!!

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

Cory Anderson Wed, 11/19/2014 - 15:48
User Badges:

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?

 

Thanks,

Cory

Joe Clarke Thu, 11/20/2014 - 07:54
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

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".

Actions

This Document