[Contents] [Prev] [Next] [Index] [Report an Error]

Displaying DNS Hostname Information

This script displays Domain Name System (DNS) information for a routing platform in your network. The script offers a slight improvement over the show host hostname command because you do not need to enter a hostname or IP address to view DNS information for the routing platform you are currently using.

There is no JUNOS Extensible Markup Language (XML) equivalent for the show host hostname command. Therefore, this script uses the show host hostname command directly rather that using a remote procedure call (RPC). For more information, see Using RPCs and Operational Mode Commands.

The script is shown as two distinct versions. These two versions accept the same argument and produce the same output. Version 1 uses the <xsl:choose> element. Version 2 uses the jcs:first-of() function.

XSLT Syntax 1: <xsl:choose>

<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:junos="http://xml.juniper.net/junos/*/junos"
    xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
    xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">

    <xsl:import href="../import/junos.xsl"/>

    <xsl:variable name="arguments">
        <argument>
            <name>dns</name>
            <description>Name or IP address of a host</description>
        </argument>
    </xsl:variable>

    <xsl:param name="dns"/>

    <xsl:template match="/">
        <op-script-results>

            <xsl:variable name="query">
                <xsl:choose>
                    <xsl:when test="$dns">
                        <command>
                            <xsl:value-of select="concat('show host ', $dns)"/>
                        </command>
                    </xsl:when>
                    <xsl:when test="$hostname">
                        <command>
                            <xsl:value-of select="concat('show host ', $hostname)"/>
                        </command>
                    </xsl:when>
                </xsl:choose>
            </xsl:variable>

            <xsl:variable name="result" select="jcs:invoke($query)"/>
            <xsl:variable name="host" select="$result"/>
            <output>
                <xsl:value-of select="concat('Name: ', $host)"/>
            </output>
        </op-script-results>
    </xsl:template>
</xsl:stylesheet>

XSLT Syntax 2:
jcs:first-of()

<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:junos="http://xml.juniper.net/junos/*/junos"
    xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
    xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">

    <xsl:import href="../import/junos.xsl"/>

    <xsl:variable name="arguments">
        <argument>
            <name>dns</name>
            <description>Name or IP address of a host</description>
        </argument>
    </xsl:variable>

    <xsl:param name="dns"/>

    <xsl:template match="/">
        <op-script-results>

            <xsl:variable name="target" select="jcs:first-of($dns, $hostname)"/>
            <xsl:variable name="query">
                <command>
                    <xsl:value-of select="concat('show host ', $target)"/>
                </command>
            </xsl:variable>

            <xsl:variable name="result" select="jcs:invoke($query)"/>
            <xsl:variable name="host" select="$result"/>
            <output>
                <xsl:value-of select="concat('Name: ', $host)"/>
            </output>
        </op-script-results>
    </xsl:template>
</xsl:stylesheet>

SLAX Syntax 1: <xsl:choose>

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

var $arguments = {
    <argument> {
        <name> "dns";
        <description> "Name or IP address of a host";
    }
}
param $dns;

match / {
    <op-script-results> {
        var $query = {
            if ($dns) {
                <command> 'show host ' _ $dns;

            } else if ($hostname) {
                <command> 'show host ' _ $hostname;
            }
        }
        var $result = jcs:invoke($query);
        var $host = $result;
        <output> 'Name: ' _ $host;
    }
}

SLAX Syntax 2:
jcs:first-of()

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

var $arguments = {
    <argument> {
        <name> "dns";
        <description> "Name or IP address of a host";
    }
}
param $dns;

match / {
    <op-script-results> {
        var $target = jcs:first-of($dns, $hostname);
        var $query = {
            <command> 'show host ' _ $target;
        }
        var $result = jcs:invoke($query);
        var $host = $result;
        <output> 'Name: ' _ $host;
    }
}

[Contents] [Prev] [Next] [Index] [Report an Error]