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 hosthostnamecommand 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 hosthostnamecommand. Therefore, this script uses theshow hosthostnamecommand 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 thejcs:first-of()function.Version 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>Version 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>Testing ex-hostname.xsl
To test the example in this section, perform the following steps:
- From Displaying DNS Hostname Information, copy the Extensible Stylesheet Language Transformations (XSLT) script into a text file, and name the file ex-hostname.xsl. Copy the ex-hostname.xsl file to the
/var/db/scripts/opdirectory on your routing platform.- Include the file ex-hostname.xsl statement at the
[edit system scripts op]hierarchy level:[edit system scripts op]file ex-hostname.xsl;- Issue the
commit and-quitcommand.- When you issue the
op ex-hostnameoperational mode command without thednsargument, the DNS information is displayed for the router you are currently using:[edit]user@host#op ex-hostnameName:this-router has address 10.168.71.246When you issue the
op ex-hostnamednshostnamecommand, the DNS information is displayed for the specified router:[edit]user@host#op ex-hostname dns router1Name:router1 has address 10.168.71.249When you issue the
op ex-hostnamednsaddresscommand, the DNS information is displayed for the specified address:[edit]user@host#op ex-hostname dns 10.168.71.249Name:249.71.168.10.IN-ADDR.ARPA domain name pointer router1